Displaying 20 results from an estimated 20000 matches similar to: "expand.grid applied to a matrix"
1999 Nov 11
2
dimname'less array breaks apply (PR#318)
<<insert bug report here>>
> apply(array(1:20,c(2,2,5)),2:3,function(x) x)
Error: length of dimnames must match that of dims
>
Changing:
dimnames = if (is.null(dn.ans)) list(ans.names, NULL) else c(list(ans.names), dn.ans)
To:
dimnames = if (length(dn)==0) NULL else
if (is.null(dn.ans)) list(ans.names, NULL) else c(list(ans.names), dn.ans)
seems to fix this.
Chuck
2010 Nov 25
1
Request: kronecker to get a sep= argument
kronecker, with make.dimnames=TRUE uses a hardwired sep=":" in the line
tmp <- outer(dnx[[i]], dny[[i]], FUN = "paste", sep = ":")
For an application in which dimnames arise from an n-way array, where
different dimensions have
different roles, and I would like to be able to use kronecker in the form
kronecker(A, B, make.dimnames=TRUE,
2008 Aug 08
1
operating on arrays of unknown dimensionality
Dear R-users,
I am looking for a way to assign to slices of arrays where dimensionality of the array is not a-priory known.
Specifically, I would like to be able to generalize the following example of dimensionality 2 to an arbitrary diminsionality:
In this example we create an array x, a smaller array y and then assign y to a slice of x.
> dimnmx <- list(c('a','b'),
2008 Jan 04
3
slow access to matrix dimnames
hello,
i have been trying to convert my data frames to matrices in the hopes of
speeding up some of my more complicated scripts.
to assist with this, i am trying to create a "matrix column operator"
like $:
"%$%" = function(data,field) {
as.numeric(data[,grep(field,unlist(dimnames(data)[2]))])
}
the idea here is that you can use a matrix like a dataframe:
2008 Aug 29
1
lost attrubute:names
Hi,
when I pick out one element from a matrix, the attribute name is kept, but when
more than one elements are extracted, the attribute name lost;
>a<-matrix(c(1,2,3,11,12,13,45,56,76),ncol=3,dimnames=list(c(),c("c1","c2","c3")))
> k<-a[a[,"c3"]>50,"c3"]
> kk<-a[a[,"c3"]>60,"c3"]
> attributes(k)
NULL
2009 Jan 27
2
working with tables -- was Re: Mode (statistics) in R?
Ok, so I'm slowly figuring out what a factor is, and was able to follow
the related thread about finding a mode by using constructs like
my_mode = as.numeric(names(table(x))[which.max(table(x))])
Now, suppose I want to keep looking for other modes? For example,
Rgames> sample(seq(1,10),50,replace=TRUE)->bag
Rgames> bag
[1] 2 8 8 10 7 3 2 9 8 3 8 9 6 6 10 10 7 1
2007 Dec 17
2
more structure than 'str'?
How can I see more of the structure than displayed by 'str'?
Consider the following:
tstDF <- data.frame(a=1, row.names='b')
> str(tstDF)
'data.frame': 1 obs. of 1 variable:
$ a: num 1
The object 'tstDF' has row.names, but I have to suspect they are
there -- AND know a function like 'row.names' or 'dimnames' -- to see
2009 Dec 03
3
dataset index
Hello, All,
I have a dataset that looks like this:
x <- matrix(c(
0, 0, 0,
0, 0, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
1, 2, 1,
1, 2, 1,
1, 3, 1,
1, 3, 1,
1, 3, 1),
ncol = 5, byrow = T,
dimnames = list(1:10, c("gender", "race", "disease")))
I want to write a function to produce several matrices including only ?TRUE?
and ?FALSE? for the different levels of the
2007 Aug 07
1
Naming Lists
Hi
Im pretty new to R and I have run in to a problem. How do I name all the
levels in this list.
Lev1 <- c("A1","A2")
Lev2 <- c("B1","B2")
Lev3 <- c("C1","C2")
MyList <- lapply(Lev1,function(x){
lapply(Lev2,function(y){
lapply(Lev3,function(z){
paste(unlist(x),unlist(y),unlist(z))
})})})
I would like to name the different
2009 Jan 19
1
further notes on model.frame issue
This is a follow-up on my note of Saturday. Let me start with two important
clarifications
- I think this would be a nice addition, but I've had exactly one use for it
in the 15+ years of developing the survival package.
- I have a work around for the current case.
Prioritize accordingly.
The ideal would be to change survexp as follows:
fit <- survexp( ~ gender,
2010 Jan 21
2
Problems completely reading in a "large" sized data set
I have been through the help file archives a number of times, and still
cannot figure out what is wrong.
I have a tab-delimited text file. 76Mb, so while it's large.. it's not
-that- large. I'm running Win7 x64 w/4G RAM and R 2.10.1
When I open this data in Excel, i have 27 rows and 450932 rows, excluding
the first row containing variable names.
I am trying to get this into R as a
2009 Dec 16
1
number of observations used in cor when use="pairwise.obs"
Dear R gurus,
to compute the correlation matrix of "n" variables with "n_obs" observations
each,
possibly including NA, I use cor(M, use="pairwise.obs")
where m is a "n" x "nobs" matrix.
Now I want to know the number of observations actually used in this
computation,
namely for each pair of columns in M, say pair (i,j), I want to compute
sum(
2011 Aug 21
1
Multiple R linear models into one Latex table
Dear community,
I had been looking for an easy way to produce latex tables from R
output. xtable() and the package apsrtable produce good outputs but they are not
exactly what I was looking for.
I wrote this code that generates regression tables from multiple R
linear models. I want to share it because it might be
useful for someone else, and because I would appreciate comments on how to
2007 Feb 06
2
abbreviate dataframe for Sweave output
I wanted to print the first and last rows of some dataframes in Sweave
using dots in columns to separate the two parts. Head and tail almost
work, but I have problems with factors and row names.
z<-data.frame(id=letters[1:26], x=sample(1:26,26))
rbind(head(z,3), ".", tail(z,1))
id x
1 a 18
2 b 8
3 c 14
4 <NA> .
26 z 10
Warning message:
invalid
2007 Apr 18
3
Matrix or grid conversion of spatial data
Dear Happy R-users & experts,
I am in need of advice,
While working with spatial data (x & y coordinates of seed locations) I have come accross the problem that I need to convert my point data into a matrix or grid system. I then need to count how often a point falls into a certain position in the matrix or grid. I have searched all day online, asked collegeas but nothing works.
Sadly
2009 Oct 13
7
lapply() reccursively
Hi all,
I was wondering whether it is possible to use the lapply() function
to alter the value of the input, something in the spirit of :
a1<-runif(100)
a2<-function(i){
a1[i]<-a1[i-1]*a1[i];a1[i]
}
a3<-lapply(2:100,a2)
Something akin to a for() loop, but using the lapply() infrastructure.
I haven't been able to get rapply() to do this.
The reason is that the "real"
2006 Dec 10
4
sample "n" random positions from a matrix
Hi there,
I have a binary matrix (dim 100x100) filled with values 0 and 1. I need select a record "n" positions of that matrix when values are 1. How can I do that?
Thanks for all,
Miltinho
Brazil
---------------------------------
[[alternative HTML version deleted]]
2001 Oct 08
1
NA as names of vector from subscripted matrix == bug ?
Is this a bug?
> matrix(1:4,nc=2,dimnames=list(1:2,1:2))[c(1,3)]
1 NA
1 3
It has some annoying consequences, e.g.
> median( matrix(1:9,nc=3,dimnames=list(1:3,1:3))[1,,drop=F] )
NA
4
>
The above was for
Version:
platform = sparc-sun-solaris2.7
arch = sparc
os = solaris2.7
system = sparc, solaris2.7
status =
major = 1
minor = 3.0
year = 2001
month = 06
day = 22
2010 Jul 07
3
How do I test against a simple null that two regressions coefficients are equal?
Hi there,
I run two regressions:
y = a1 + b1 * x + e1
y = a2 + b2 * z + e2
I want to test against the null hypothesis: b1 = b2. How do I design the test?
I think I can add two equations together and divide both sides by 2:
y = 0.5*(a1+a2) + 0.5*b1 * x + 0.5*b2 * z + e3, where e3 = 0.5*(e1 + e2).
or just y = a3 + 0.5*b1 * x + 0.5*b2 * z + e3
If I run this new regression, I can test against
2009 Oct 01
1
Using optimize with array variables
Hello,
I am trying to figure out how to use optimize() with array variables
as inputs. I have a for loop in the function definition:
SS <- function(int,slo,x,y){
for(i in 1:length(x)) ((int+slo*x[i])-y[i])^2->squares[i]
sum(squares)->>sum_squares
output_txt = c ("The sum of squares is", sum_squares)
print(output_txt, quote=FALSE)}
Even assuming I make x and y