[R] Excluding columns from dataframe and selecting row records

Logan Lewis lr at proxc.net
Sun Sep 17 22:27:02 CEST 2006


Miltinho,

On Sun, Sep 17, 2006 at 05:08:29PM -0300, Milton Cezar wrote:
> Dear R-friends,
>
>   I have to simple questions. First I would like to exclude some 
columns from a dataframe and after I need select rows that satisfy some 
conditions.
>   My data frame looks like
>
>   Region Species Bodysize Weigth Age
>   Africa  Sp1 10.2 20 2
>   Africa  Sp2 12.2 12 2
>   Africa  Sp3 15.3 18 3
>   Africa  Sp4 11.5 40 4
>   Brazil  Sp1 10.2 40 3
>   Brazil  Sp2 22.2 32 2
>   Brazil  Sp3 12.3 28 3
>   Brazil  Sp4 21.5 30 5
>
>   And I need for example only "columns" Bodysize Weigth and Age when 
Region=="Brazil" AND Species=="Sp2" AND Age>=3
>
The "subset" command should suit your needs: subset(dataframe,
Region=="Brazil" && Species=="Sp2" && Age>=3,select =
c("Bodysize","Weigth","Age"))

See help(subset) for more info.

Regards,
Logan



More information about the R-help mailing list