[R] looking up value from a pair of vectors
Stefann Jonsso
stefanhrafnjonsson at hotmail.com
Mon Apr 19 12:34:55 CEST 2004
Hello R community.
Can anyone inform me how to solve this short problem? I have a dataset that
I want to recode according to a pair of short numerical vectors. Here is a
short example:
# Start R code
map1 <- matrix(ncol=3, byrow=T,c( 197796,"label0",1,
197797,"label1",2,
197798,"label2",3,
197799,"label3",4,
197800,"label4",5))
xx <- as.integer(map1[,1])
lab <- map1[,2]
yy <- as.integer(map1[,3]
data1a <- c(197797, 197798, 197799, 197800,
197797, 197797, 197797, 197797)
data1b <- some.function.or.combinaion.of.few(data1a,xx,yy)
# desired result for data1b
data1b
2 3 4 5 2 2 2 2
# End R code
data1a is always longer than xx.
all numerical entries in data1a are members of xx. (in the more general
problem, the the number 197796 may or may not be included in data1a)
value in data1a that are not members of xx would produce a "Na"
Thanks in advance for all replies,
Stefan Jonsson
More information about the R-help
mailing list