[R] Selecting data frame components by name - do you know a shorter way?

Douglas Grove dgrove at fhcrc.org
Fri Jan 20 19:00:05 CET 2006


So you want to create a subset of a data frame?
with components "name1" "name2" "name3" ... 

dframe[, c("name1","name2","name3",...)]   

will do that

Doug



On Fri, 20 Jan 2006, Michael Reinecke wrote:

> Hi! I suspect there must be an easy way to access components of a data frame by name, i.e. the input should look like "name1 name2 name3 ..." and the output be a data frame of those components with the corresponding names. I ´ve been trying for hours, but only found the long way to do it (which is not feasible, since I have lots of components to select):
> 
>  
> 
> dframe[names(dframe)=="name1" | dframe=="name2" | dframe=="name3"]
> 
>  
> 
> Do you know a shortcut?
> 
>  
> 
> Michael
> 
> 
> 	[[alternative HTML version deleted]]
> 
> 


More information about the R-help mailing list