[R] how to order each element according to alphabet

David Winsemius dwinsemius at comcast.net
Fri Jul 15 04:45:21 CEST 2011


On Jul 14, 2011, at 9:18 PM, onthetopo wrote:

> Hi there,
>
>  I have a large amino acid csv file like this:
>
> input.txt:
> P,LV,Q,Z
> P,VL,Q,Z
> P,ML,QL,Z
>

Are you also asking how to read a comma separated file?

? read.csv   # and read more introductory material


> There is a problem with this file, since LV and VL are in fact the  
> same
> thing.
> How do I order each element according to alphabetical order so that  
> the
> desired output would look like:
>
> output.txt:
> P,LV,Q,Z
> P,LV,Q,Z
> P,LM,LQ,Z
>

That is not a reproducible example without input code:

Perhaps:

as.data.frame(lapply(input_dfrm, gsub, patt="LV", repl="VL"))

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list