Rainer provided an example of subsetting by the value of a variable in the 
data frame.  Below is an example of subsetting by the value of the row 
name of the data frame.

df <- data.frame(var1=1:10, var2=letters[1:10], var3=sample(10), 
     row.names=month.abb[1:10])
subset(df, subset = row.names(df) %in% c("Feb", "Jul", "Sep"), 
     select=c(var1, var2))

    var1 var2
Feb    2    b
Jul    7    g
Sep    9    i

Jean


Rainer Schuermann wrote on 09/09/2011 07:44:11 AM:
> 
> Does that help:
> 
> > x
>       xin     xout
> 1       1       14
> 2       8        5
> 3      16      884
> 4       1       14
> 5       8        5  
> 6      16      884
> 
> > subset( x, x$xin > 7, select = xout )  
>       xout  
> 2        5  
> 3      884  
> 5        5  
> 6      884 
> 
> Rgds,
> Rainer
> 
> 
> On Friday 09 September 2011 04:38:44 stat.kk wrote:
> > Hi,
> > 
> > can anyone help me how to use 'subset' function on my data frame?
> > I have created data frame 'data' with a few variables and with row 
names.
> > Now I would like to subset rows with concrete row names.
> > Using data[] I know how to do it. But I dont know how to formulate the
> > subset condition:
> > subset(data, subset = ?, select = c(var1, var2))
> > 
> > Thank you very much,
> > stat.kk
> > 

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to