[R] (no subject)

Sarah Goslee sarah.goslee at gmail.com
Tue Jul 26 17:41:54 CEST 2011

# for, e.g., four random individuals
x.sub<-data[data$ID %in% sample(1:16, 4),]

On Tue, Jul 26, 2011 at 10:10 AM, Soanes, Louise
<Louise.Soanes at liverpool.ac.uk> wrote:
> Hello
> I have been trying to figure out how to randomly select a number of records. I have a column "ID" which contains 16 individuals (numbered 1-16), each individual has a few hundred rows of GPS locations associated with it. I am trying to select a random sample of these individuals (with all their associated GPS locations) to run a kernel density analysis on, and need to repeat this several hundred times for each number of individuals in a sample.
> For example: I would like to be able to randomly select all the data associated with 2 individuals (out of my 16) 100 times to run the analysis on and then randomly select 3 individuals from my 16 individuals 100 times.... and then randomly select 4 individuals 100 times ....and so on.
> At the moment I am using:
> data<-read.csv("All.csv")
> x.sub<-data[data$ID %in% c(10,8),]
> I have just been typing in random numbers to select individuals from my total number of 16 for the subsampling which was ok when I just wanted 2 individuals from my 16 but as I include more individuals in my sample this is becoming more painstaking! So does anybody know how I can write a command so that R randomly selects a specified number of individuals from my ID column.
> If anybody can help I would really appreciate it
> Many thanks
> Louise Soanes
> University of Liverpool

Sarah Goslee

More information about the R-help mailing list