Re: [R] sampling problem - new to R

From: Doran, Harold <HDoran_at_air.org>
Date: Wed, 06 Jun 2007 09:56:42 -0400


I dealt with something like this recently.

x <- data.frame(plot = gl(2,5), tree = rnorm(10)) y <- split(x, x$plot)

ss <- numeric(2)
for(i in 1:2){

        ss[i] <- sample(row.names(y[[i]][1]), 1) }

z <- x[ss,]

People help out of the goodness of the hearts and not for publication recognition.

Harold

> -----Original Message-----
> From: r-help-bounces_at_stat.math.ethz.ch
> [mailto:r-help-bounces_at_stat.math.ethz.ch] On Behalf Of baldeck
> Sent: Tuesday, June 05, 2007 10:30 AM
> To: r-help_at_stat.math.ethz.ch
> Subject: [R] sampling problem - new to R
>
>
> I have a data set of individual trees and the plots that they are in:
>
> Tree Plot
> 56749 1
> 63494 1
> 87375 1
> 37494 2
> 92753 3
> 34847 3
> 38747 4 etc...
>
> So each plot is represented once for every individual that
> occurrs in it.
> Plots get different numbers of rows because there can be a
> different number of individuals in each plot.
>
> I want to make a data frame that consists of one individual
> from each plot.
> I would like to randomly choose one individual from each plot
> that is present in the data set. I will have to do this to
> multiple data sets which may contain different plots, and may
> contain up to 1200 plots, so I can't choose the plots by hand.
>
> Please help me with this. I'm an ecologist and I'm in
> Panama, with no one around who is educated in R. Whoever
> solves this problem for me will be acknowledged in any
> resulting publications.
>
> Thanks!
> -Claire
> --

> View this message in context:
> http://www.nabble.com/sampling-problem---new-to-R-tf3872130.ht
> ml#a10970708
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch 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.
>



R-help_at_stat.math.ethz.ch 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 06 Jun 2007 - 14:32:15 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 06 Jun 2007 - 15:01:37 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.