Lainaus "Uwe Ligges" <lig...@statistik.tu-dortmund.de>:
On 05.03.2010 15:24, kloyt...@mappi.helsinki.fi wrote:
Hi,
I have a list p with different size dataframes and length of over 8000.
I'm trying to
calculate correlations between the rows of dataframes of this list and
columns of another
dataset (type data.frame also) so that first column is correlated with
all the rows in
the list dataframe. Some information from another dataset is also
included to the final
output (all.corrs). This worked a couple of weeks ago when I wrote it
but now it seems
not to, and gives an error message:
Error in inherits(x, "data.frame") : subscript out of bounds
In addition: There were 50 or more warnings (use warnings() to see the
first 50)
warnings()
Warning messages: 1: In corrs[j] <- cbind(expressions[j, 1:5],
SNP.expr.cor) :
number of items to replace is not a multiple of replacement length
which indicates that the problem is with getting correlation and other
information into
corrs. cbind(expressions[j,1:5], SNP.expr.cor) is type data.frame.
Changing corrs into
matrix, dataframe, list or any other type has not helped.
I've updated R from 2.9.0 to the recent version in between. Would anyone
have a solution
for this problem? I very much appreciate all help.
SNP.expr.cor<-NULL
all.corrs<-NULL
corrs<-NULL
for(i in 1:length(p)){
dim.exp<-dim(p[[i]])
expressions<-p[[i]]
expressions.m<-as.matrix(expressions[,6:48])
for(j in
1:dim.exp[1]){
SNP.expr.cor<-cor(genotypes[,i],expressions.m[j,],use="na.or.complete")
corrs[j]<-cbind(expressions[j,1:5], SNP.expr.cor)
}
all.corrs[i]<-list(cbind(map[i,1:6], corrs))
}
BR
Katja
Your example is not reproducible, since we do not have the data.
What I guess is that you need to make your objects lists in advance.
I cannot try out, but maybe the following works better right away
all.corrs <- vector(mode = "list", length = length(p))
for(i in seq(along = p)){
dim.exp <- dim(p[[i]])
corrs <- vector(mode = "list", length = dim.exp[1])
expressions <- p[[i]]
expressions.m <- as.matrix(expressions[,6:48])
for(j in 1:dim.exp[1]){
SNP.expr.cor <- cor(genotypes[, i], expressions.m[j, ], use
= "na.or.complete")
corrs[[j]] <- cbind(expressions[j, 1:5], SNP.expr.cor)
}
all.corrs[[i]] <- list(cbind(map[i, 1:6]), corrs)
}
Best,
Uwe Ligges
Hi, sorry about that, here's a new try:
corrs<-NULL #I've tried everything from vector to matrix to data.frame to list
a<-rnorm(30)
b<-cbind(a,a,a,a,a)
e<-as.matrix(t(b))
c<-c("one", "two", "three", "four", "five")
d<-c("one", "two", "three", "four", "five")
c<-rbind(c,c,c,c,c)
k<-dim(dat)
for(j in 1:k[1]){
dat.cor<-cor(b[,i],e[j,],use="na.or.complete")
corrs[j]<-cbind(c[j,1:5], dat.cor)
}
The trouble seems to be in the inner loop. I'd love to have it as
data.frame or matrix, not as a list. I think there has been similar
problems presented here before but I haven't been able to find a
working solution yet.
BR
Katja Löytynoja
--
Katja Löytynoja, M.Sc.
Haartman Institute
Department of Medical Genetics
Biomedicum Helsinki
P.O.Box 63
FIN-00014 University of Helsinki
tel +358-9-19125496
gsm +358-50-4000324
fax +358-9-19125624
e-mail katja.loytyn...@helsinki.fi
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.