[R] Problem with lapply
rissa
rissa_r at gmx.ch
Tue Oct 15 18:55:38 CEST 2013
Hi together
I'm pretty new to R, so excuse me if it is a basic question.
I have a big dataset (extract of it found in the attachment) of returns from
firms. I'd like to compute the Pearson correlation of each firm with the
"Market" and the corresponding p-Value. So I thought of making a list of
'cor.test's and then extract the needed values with a for loop. What I did
so far...
dataset=Testcor
dataset$DATE<-as.Date(dataset$DATE,"%Y-%m-%d")
firm.names=colnames(dataset)[2:length(colnames(dataset))]
cor.results1=lapply(firm.names,function(x)cor.test(as.formula(paste(firm.names[firm.names==x],Market)),data=dataset,na.action=na.exclude))
But I always get error messages like
Error in paste(firm.names[firm.names == x], Market) :
object 'Market' not found
or (when I attach dataset)
Error in parse(text = x) : <text>:1:6: unexpected numeric constant
1: PAXN NA
(Next step would have been something like
for(i in 1:ncol(cor.results1)){
newmatrix[1,i]= cor.results1 [[i]]$estimate}
etc)
Could you please help me?
Thank you so much!
Rissa
Testcor.txt <http://r.789695.n4.nabble.com/file/n4678290/Testcor.txt>
--
View this message in context: http://r.789695.n4.nabble.com/Problem-with-lapply-tp4678290.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list