[R] Calculating sum of letter values

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Mon Nov 24 16:24:21 CET 2008


> Thanks, that's almost exactly what I need...theres just a slight 
> difference with my requirement, in that I am looking for the actual 
> index value in the alphabetical sequence, so that instead of:
> 
> as.numeric(factor(unlist(strsplit("XYZ",""))))
> [1] 1 2 3
> 
> I would expect to see
> 
> [1] 24 25 26

A minor modeification of Mark's solution works in this case:

as.numeric(factor(unlist(strsplit("XYZ", "")), levels=LETTERS))
# [1] 24 25 26

Regards,
Richie.

Mathematical Sciences Unit
HSL



------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}



More information about the R-help mailing list