[R] extraction from data.frame

David Winsemius dwinsemius at comcast.net
Sun Oct 4 19:19:17 CEST 2009


On Oct 4, 2009, at 12:09 PM, <sabrina.michielin at alice.it> wrote:

> Hi,
> I extracted from a data.frame (x) of 27 columns a smaller data.frame  
> (x2) with 12 columns whit the following:
>
> x2=x[, c("BROVISINGVal", "CHATVal", "EMAILVal", ...,  
> "Piano.Tariffario")]

Something like this (untested):

x2=x[ x$Piano.Tariffario == 2 , c("BROVISINGVal", "CHATVal",  
"EMAILVal", ..., "Piano.Tariffario")]

Logical vectors, such as that created by x$Piano.Tariffario == 2 , are  
often used in the row postion of an extraction using "[ , ]" indexing.


>
> Anyway I want to form x2 by extracting all the rows that assume any  
> value for the first 11 columns but a particular value (2) for the  
> last one "Piano.Tariffario".
> How do I continue?
> Thanks
> Sabrina


David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list