[R] Odp: Odp: sampling problem - new to R
Petr PIKAL
petr.pikal at precheza.cz
Wed Jun 6 16:11:13 CEST 2007
> Hi
>
> If I understand correctly, use split and sample with lapply. If DF is
your dataframe
>
> lapply(split(DF$Tree, DF$Plot), function(x) sample(x,1))
>
> shall select random tree from each plot. Or you can get it in tabular
form with sapply.
>
> Regards
> Petr
Sorry, you shall use resample from sample help page as Prof.Ripley pointed
if you can have length<=1 plot.
Regards
Petr
>
> r-help-bounces at stat.math.ethz.ch napsal dne 05.06.2007 16:29:49:
>
> >
> > 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.html#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.
More information about the R-help
mailing list