[R] From strings to numbers
Chuck Cleland
ccleland at optonline.net
Mon May 19 13:29:08 CEST 2008
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
More information about the R-help
mailing list