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

2015-10-09 Thread peter dalgaard
A set of curlies should help.

As in
> replicate(5, {y <- runif(20); mean(y)})
[1] 0.4926800 0.5356511 0.5343938 0.5313422 0.5287927

-pd

BTW: sum(replicate(1,...))/1 is simpler and less error-prone written as 
mean(replicate(1,))

> On 09 Oct 2015, at 01:37 , Curtis Browne  wrote:
> 
> 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(1,data$Scram <- sample(data$Changeinmass,10, replace = 
> FALSE); with(data,cor(Current,data$Scram))>=0.9796619))/1
> 
> With the error:
> 
> Error: unexpected ';' in "sum(replicate(1,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]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] Help with replicate

2008-11-27 Thread Alex99


Hello everyone,
I have a file called trans which has 100 records (rows) and 60 columns.
I need to make 2 samples (with 5 records in each) out of this file with no
replacement, so I used replicate.
The sampling part works fine and I called the outcome result.

my problem is then I need to calculate the correlation matrix for each
sample. I used do.call and called the outcome CORE. but the problem is
when I get my out put it's not separated for each sample. they are all
together and I need them to be separated. just to give U an idea I copy and
paste the out put:

  616783805134   
217
616  1. -0.08522865 -0.15018785 -0.12462239 -0.04279605
783 -0.08522865  1. -0.02986738 -0.04731350  0.33191790
805 -0.15018785 -0.02986738  1.  0.15483873 -0.08998425
134 -0.12462239 -0.04731350  0.15483873  1.  0.16290948
217 -0.04279605  0.33191790 -0.08998425  0.16290948  1.
607  1. -0.12662932  0.16116459 -0.03479445 -0.03479445   *(from
here is for the 2nd sample)
604 -0.12662932  1.  0.01298701 -0.06168397 -0.06168397
698  0.16116459  0.01298701  1. -0.03925343 -0.03925343
639 -0.03479445 -0.06168397 -0.03925343  1. -0.01694915
989 -0.03479445 -0.06168397 -0.03925343 -0.01694915  1.
  
does any one has any idea how can I separate the result for 2 samples? 

This is my code:
result=replicate(2,trans[,sample(colnames(trans),5,replace =
FALSE)],simplify=FALSE)
CORE=do.call(rbind,lapply(result,function(x) cor(x)))

-- 
View this message in context: 
http://www.nabble.com/Help-with-%22replicate%22-tp20722891p20722891.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.