[R] Subsetting by number of observations in a factor
ron.crump at une.edu.au
Fri Aug 10 05:30:27 CEST 2007
> Does this do what you want? It creates a new dataframe with those
> 'mg' that have at least a certain number of observation.
Looks good. I also have an alternative solution which appears to work,
so I'll see which is quicker on the big data set in question.
mgsize <- as.data.frame(table(in$mg))
in2 <- merge(in,mgsize,by.x="mg",by.y="Var1")
out <- subset(in2, Freq > 1, select= -Freq)
Thanks for your help.
More information about the R-help