On 5/19/2008 6:13 AM, 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)

X <- c("ab","ab","bb","cat","cat","ab")

as.numeric(as.factor(X))

[1] 1 1 2 3 3 1

Thx,
Naira

--
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

______________________________________________
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