Naira wrote:
Dear all,

I would like to know if there is an easy to transform a vector of strings to
a vector of integers.
Ex: ("ab","ab","bb","cat","cat","ab") will be
(1, 1, 2, 3, 3, 1)

Hi Naira,
It's not all that hard...

newfactor<-as.factor(c("ab","ab","bb","cat","cat","ab"))
 newfactor
[1] ab  ab  bb  cat cat ab
Levels: ab bb cat
as.numeric(newfactor)
[1] 1 1 2 3 3 1

Jim

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to