[R] letters to numbers conversion

Andrew C. Ward s195404 at student.uq.edu.au
Fri May 2 06:42:41 CEST 2003


How about the following?
   t1 <- matrix(letters[1:9], nrow=3, byrow=TRUE)
   t1
   t2 <- t(apply(t1, 1, function(x) match(x, letters)))
   t2


Regards,

Andrew C. Ward

CAPE Centre
Department of Chemical Engineering
The University of Queensland
Brisbane Qld 4072 Australia
andreww at cheque.uq.edu.au
  
   
Quoting Robin Hankin <r.hankin at auckland.ac.nz>:

> Hello List
> 
> How do I turn
> 
> R> simple.example.alphabetic
>      [,1] [,2] [,3]
> [1,] "a"  "b"  "c" 
> [2,] "d"  "e"  "f" 
> [3,] "g"  "h"  "i" 
> 
> into
> 
> R> simple.example.numeric
>      [,1] [,2] [,3]
> [1,]    1    2    3
> [2,]    4    5    6
> [3,]    7    8    9
> 
> [ie "a" becomes 1, ..., "z" becomes 26]
> ?
> 
> 
> 
> 
> 
> 
> -- 
> 
> Robin Hankin, Lecturer,
> School of Geography and Environmental Science
> Tamaki Campus
> Private Bag 92019 Auckland
> New Zealand
> 
> r.hankin at auckland.ac.nz
> tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>



More information about the R-help mailing list