Dear all,
Through the following code, I wanted to perform correlation test repetedly
(through loop) on different combinations of variables of a data set.
Code:
x=read.table("sample.txt",header=T,sep="\t")
out="corout.txt"
sink(out)
nm = names(x)
print(nm)
nvr=3
# nvr=Total no. of variables in the input data file
for (i in 1:(nvr-1))
{
for(j in (i+1):nvr)
{
frm= as.formula(paste(nm[i+1],",",nm[j+1],sep="")) ($$)
crl=cor.test(frm,alternative="two.sided",method="pearson")
smr=summary(crl)
print(smr)
}
}
sink()
Sample Data:
S No V1 V2 V3
1 15 10 4
2 6 4 7
3 10 5 2
4 8 6 6
But the code does not work; there seems to be some problem in the statement
marked ($$) above. The message I get is:
Error in parse(text = x) : unexpected ',' in "V1,"
Kindly help to get rid of the bug
Regards
ajss
Unlimited freedom, unlimited storage. Get it now, on
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
______________________________________________
[email protected] 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.