[R] Working with text data/text operators

Romain Francois romain.francois at dbmail.com
Tue Jan 19 13:33:41 CET 2010


On 01/19/2010 01:22 PM, Mihai.Mirauta at 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



More information about the R-help mailing list