[R] removing fields of the same group from a data frame

Henrique Dallazuanna wwwhsd at gmail.com
Wed Mar 24 14:59:16 CET 2010


Try this:

subset(foo, v3 %in% names(which(!table(foo$v3) < 3)))

On Wed, Mar 24, 2010 at 10:38 AM, Oscar Franzén
<oscar.franzen2 at gmail.com> wrote:
> Dear all,
>
> I'm trying to find a a way to remove certain fields belonging to the same
> group from a data frame structure.
>
> I have a data frame like this:
>
>  foo v1 v2 v3
>       1  1  a
>       6  2  a
>       3  8  a
>       4  4  b
>       4  4  b
>       2  1  c
>       1  6  d
>
> Each row can then be grouped according to the third column: a, b, c, d. Then
> I would like to remove all fields that belong to a group with less than X
> members, for example less than 3 members, then
> the resulting data frame structure would look like:
>
>
>  foo v1 v2 v3
>       1  1   a
>       6  2   a
>       3  8   a
>
> Is there some simple way to do this in R?
>
> Thanks in advance.
> /Oscar
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list