[R] Help using "replicate()" for two commands

Curtis Browne curtis_browne97 at hotmail.com
Fri Oct 9 01:37:19 CEST 2015


I would like to essentially do a randomization p-test (10,000 replications in this case) to check how often I would see a linear correlation in my data as strong or stronger than I did with the original data (with a correlation value of 0.9796619). The code which I thought would work is below:

sum(replicate(10000,data$Scram <- sample(data$Changeinmass,10, replace = FALSE); with(data,cor(Current,data$Scram))>=0.9796619))/10000

With the error:

Error: unexpected ';' in "sum(replicate(10000,data$Scram <- sample(data$Changeinmass,10, replace = FALSE);"

Is there any method of replicating both the function of assigning a random sample of the data to a column, and the function of then performing a Pearson correlation test between data$Current and data$Scram?

	[[alternative HTML version deleted]]



More information about the R-help mailing list