[R] extract data for specific levels factor

Sarah Goslee sarah.goslee at gmail.com
Tue Oct 25 21:49:42 CEST 2011


Hi,

2011/10/25 Andrés Aragón <armandres at gmail.com>:
> Dear all,
>
> I'm trying to analyze data with the following structure:
>
> ind          cat            tx      age
> 40.2 por fol peq     vh        35
> 41.9 por fol med     vh        35
> 68.9 por fol preov   vh       35
> 71.5 por fol peq      ser       37
> 67.5  por fol med    ser       37
> 76.9  por fol preov   ser     37
> 78.7  por fol peq      otr      37
> 78.3  por fol med    otr       37
> 82.1  por fol preov   otr      37
> 83.9  por fol peq      vh       37
> 80.6  por fol med      vh      37
> 76.1  por fol preov     vh     37
> 86.9  por fol peq        ser     35
> 97.7  por fol med       ser     35
> 62.3  por fol preov     ser     35
>
>
>
> I want to separate exclusively some of factor levels  (“por fol peq”
> in the “cat” colum). I am using ggplot2  and I only can plot all of
> factors, not separately. I did try ddply without success.
> Any help is welcome.

This kind of question is *so* much easier to answer if you provide
reproducible data with dput(). This is untested because of lack of
data, but what about

newdata <- origdata[origdata$cat %in% c("por", "fol", "peq"),]

Depending on the effect you want, you may also wish to drop the
unused levels or reorder the levels using factor().

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list