[R] removing factor level represented by less than x rows
Mikkel Grum
mi2kelgrum at yahoo.com
Fri Jul 8 16:16:57 CEST 2005
In a number of different situations I'm trying to
remove factor levels that are represented by less than
a certain number of rows, e.g. if I had the dataset aa
below and wanted to remove the species that are
represented in less than 2 rows:
data(iris)
aa <- iris[1:101,]
In this case, since I can see that the species
virginica only has one row, I can write:
table(aa$Species)
setosa versicolor virginica
50 50 1
aa[aa$Species != "virginica", ]
but:
aa[aa$Species == names(table(aa$Species)> 2),]
does not work.
This must be a fairly common task with a straight
forward solution that I can't see. Any ideas?
Best wishes,
Mikkel
More information about the R-help
mailing list