Re: [R] From strings to numbers

From: Chuck Cleland <ccleland_at_optonline.net>
Date: Mon, 19 May 2008 07:29:08 -0400

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_at_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.
Received on Mon 19 May 2008 - 11:34:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 19 May 2008 - 12:30:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive