Re: [R] sampling and testing

From: Peter Alspach <PAlspach_at_hortresearch.co.nz>
Date: Thu, 13 Nov 2008 10:59:21 +1300

Kia ora Grant

The problem is that

feb[sample(nrow(feb),###),]

randomly rearrangements the rows of all columns together, and hence doesn't altering the pairing. Try

cor(feb[, col1], feb[sample(nrow(feb)), col2])

HTH .... Peter Alspach  

> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Grant Humphries
> Sent: Thursday, 13 November 2008 8:57 a.m.
> To: r-help_at_r-project.org
> Subject: [R] sampling and testing
>
> Hello everyone,
>
> I have a dataset in the following format:
>
> col1 col2
> # #
> # #
> # #
> # #
> # #
> # #
>
>
> What I want to do is:
> loop a random sample 10 times, and for each time it is
> sampled I want to run a correlation between both columns.
> What I have so far is this:
>
> >feb <- read.csv("corr.csv") # where the dataset is for February
> >attach(feb)
> >for(i in 1:10){
> > feb[sample(nrow(feb),###),] # "###" represents the
> number of rows
> > print(cor(col1,col2),)
> >}
>
>
> all this is doing for me is doing 10 correlations between all
> 10 samples at the same time. What I was thinking was to do
> something like:
> - append a sample of the data: sample1 <- sample()
> - do the correlation cor()
> - remove that sample using rm(sample1) function
> - repeat 9 more times
>
>
> any help is greatly appreciated
>
> Cheers,
> Grant Humphries
>
>
> University of Alaska Fairbanks
> -EWHALE-lab Irving I Rm 419
> 902 Koyukuk Dr.
> Fairbanks, Alaska
> 99775
> 907-474-7959
> ftgrh_at_uaf.edu
>
> ______________________________________________
> R-help_at_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.
>

The contents of this e-mail are privileged and/or confidential to the named  recipient and are not to be used by any other person and/or organisation.  If you have received this e-mail in error, please notify the sender and delete  all material pertaining to this e-mail.



R-help_at_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. Received on Wed 12 Nov 2008 - 22:03:46 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 12 Nov 2008 - 22:30:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive