How do I sub sample data by group using ddply?
Posted
by Maiasaura
on Stack Overflow
See other posts from Stack Overflow
or by Maiasaura
Published on 2010-05-27T16:49:03Z
Indexed on
2010/05/27
16:51 UTC
Read the original article
Hit count: 163
I've got a data frame with far too many rows to be able to do a spatial correlogram. Instead, I want to grab 40 rows for each species and run my correlogram on that subset.
I wrote a function to subset a data frame as follows:
samp <- function(dataf)
{
dataf[sample(1:dim(dataf)[1], size=40, replace=FALSE),]
}
Now I want to apply this function to each species in a larger data frame.
When I try something like
culled_data = ddply (larger_data, .(species), subset, samp)
I get this error:
Error in subset.data.frame(piece, ...) :
'subset' must evaluate to logical
Anyone got ideas on how to do this?
© Stack Overflow or respective owner