On 01/19/2010 01:22 PM, mihai.mira...@bafin.de wrote:

Hello,


Could someone tell me, how can I select from a dataframe only those columns 
whose names contain a certain text?

For example, if the column names are 
"Bond1.Creditclass","Bond1.Price","Bond2.Creditclass","Bond2.Price", how do I 
select only the columns corresponding to Bond1?

Thanks a lot,

Mihai

You can do things like :

> dataset[ , grepl( "^Bond1", names( dataset ) ) ]
> dataset[ , substr( names( dataset ), 1, 5 ) == "Bond1" ]

Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/KfKn : Rcpp 0.7.2
|- http://tr.im/JOlc : External pointers with Rcpp
`- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009

______________________________________________
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