[R] column name changes based on substrings
    Jeremy Z Butler 
    jerrytheshrub at hotmail.com
       
    Fri Mar  7 01:36:22 CET 2003
    
    
  
Hi peoples,
I'm trying to work out a function which will allow me to relace column names 
on the basis of substrings within the existing names. e.g.
I'd like:
   blah.Na  blah2.Na  blah3.Mg  blah4.Mg  blah5.K  blah6.K
R1       x         x         x         x        x        x
R2       x         x         x         x        x        x
...
to become:
    Na (%)    Na (%)    Mg (%)    Mg (%)  K (ppm)  K (ppm)
R1       x         x         x         x        x        x
R2       x         x         x         x        x        x
...
So based on whether the existing column name has a .Na or a .K etc. in it 
somewhere, I'd like it to be replaced with a name which I can provide i.e. 
Na (%) or K (%).
So far I can't even figure out how to replace a column name:
>aa[colnames(aa)=="blah3.Mg"]_colnames("Mg (%)")
Error in matrix(value, n, p) : No data to replace in matrix(...)
help please
Cheers Jeremy
    
    
More information about the R-help
mailing list