> el <- c("OLDa", "OLDb", "OLDc", "NEW", "ALL")
> match(y,el)
[1] 1 5 3 1 2 4 2 1 5 NA
Peter Wolf
-----------------------
Peter Dalgaard wrote:
Muhammad Subianto <[EMAIL PROTECTED]> writes:
Dear R-helper, I have a data set like:
OLDa ALL OLDc OLDa OLDb NEW OLDb OLDa ALL . . . ALL OLDc NEW
I want to convert that data as OLDa=1, OLDb=2, OLDc=3, NEW=4 and ALL=5 or the result like:
1 5 3 1 2 4 2 1 5 . . . 5 3 4
How can I do it. Thanks you for your help.
I'd do it like this:
x <- scan(what="")1: OLDa
2: ALL
3: OLDc
4: OLDa
5: OLDb
6: NEW
7: OLDb
8: OLDa
9: ALL
10:
Read 9 items
f <- factor(x,levels=c("OLDa", "OLDb", "OLDc", "NEW", "ALL") )[1] 1 5 3 1 2 4 2 1 5
as.integer(f)
______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
