[R] How to change ONLY the first character of each variable name

Mark Na mtb954 at gmail.com
Fri Jun 19 01:24:39 CEST 2009


Dear R-helpers,

I would like to adapt the following code

> names(data)<-sub("M","MOLE",names(data))

which changes any occurrence of "M" (in my variable names) to "MOLE"

such that it ONLY operates on the first character of each variable
name, i.e. M will only be changed to MOLE if it's the first character
of a variable.

I would appreciate any help you might provide. Thanks!

Mark Na




More information about the R-help mailing list