Skip to content
Prev 277486 / 398506 Next

correlations between columns for each row

Excellent, as.matrix() didn't work but switched it to as.numeric() around 
the definition of both variables in the function and it did work:

rF <- function(x, a, b) cor(as.numeric(x[a]), as.numeric(x[b]), use = 
"complete.obs")
maindata$rFcor<-apply(maindata,1,FUN=rF,a=174:213,b=214:253)

Thanks very much both of you!
Rob

-----Original Message----- 
From: R. Michael Weylandt <michael.weylandt at gmail.com>
Sent: Tuesday, November 15, 2011 9:28 PM
To: Rob Griffin
Cc: Joshua Wiley ; r-help at r-project.org
Subject: Re: [R] correlations between columns for each row

Is the whole thing a data frame? Then any multi-column subset is also a data 
frame. Try adding a as.matrix() wrapper  in the definition of rF.

Michael

On Nov 15, 2011, at 3:14 PM, "Rob Griffin" <robgriffin247 at hotmail.com> 
wrote: