Hi everyone, I'm having trouble applying the Cor() function to two matrices, both of which contain NAs. I am doing the following: a<-cor(m1, m2, use="complete.obs") ... and I get the following error message: Error in cor(m1, m2, use = "complete.obs") : no complete element pairs Does anyone know how I can apply a correlation, ignoring any NAs? Thanks, rcoder -- View this message in context: http://www.nabble.com/correlation-between-matrices---both-with-some-NAs-tp18721853p18721853.html Sent from the R help mailing list archive at Nabble.com.
rcoder
2008-Jul-30 18:01 UTC
[R] Re gression between columns in matrix - with some/full NAs
Hi Anna, Thanks for your reply and suggestions. I'm trying something different, based on regression this time, albeit giving similar problems. I want to regress a single column in a matrix with each other column in the same matrix, and o/p the intercept and slope coefficients to a results matrix. The loop below works, even when I have columns with partial NAs, but exits with an error when a column with only NAs is encountered. So, the 'na.action=NULL' statement (see last line of code below) doesn't seem to work in this case, or perhaps I am applying it incorrectly. I would be very grateful for any pointers in the right direction:>tt<-time(SourceMat) >ResultMat<-matrix(NA, ncol=colnum, nrow=rownum) #creates an o/ptemplate matrix #loop through each column in the source matrix:>for (i in 1:5000){ sel_col<-[col(SourceMat)==i] #selecting the correct column in the matrix in turn SourceMat[,i]<-coef(lm(tt~sel_col), na.action=NULL) } Thanks, rcoder rcoder wrote:> > Hi everyone, > > I'm having trouble applying the Cor() function to two matrices, both of > which contain NAs. I am doing the following: > > a<-cor(m1, m2, use="complete.obs") > > ... and I get the following error message: > > Error in cor(m1, m2, use = "complete.obs") : > no complete element pairs > > Does anyone know how I can apply a correlation, ignoring any NAs? > > Thanks, > > rcoder >-- View this message in context: http://www.nabble.com/correlation-between-matrices---both-with-some-NAs-tp18721853p18739148.html Sent from the R help mailing list archive at Nabble.com.