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
______________________________________________
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.