Milton Cezar
2006-Sep-17 20:08 UTC
[R] Excluding columns from dataframe and selecting row records
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 In fact my dataset is greater than this, but it is just a example. Thanks for all helps, Kind regards, Miltinho --------------------------------- Música para ver e ouvir: You're Beautiful, do James Blunt [[alternative HTML version deleted]]
Logan Lewis
2006-Sep-17 20:27 UTC
[R] Excluding columns from dataframe and selecting row records
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 somecolumns 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 whenRegion=="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