r - how to convert a vector of characters to quantitative data -
i have vector following data:
data<-c('ab','ab','ab','cd','cd','cd','ef','ef')   how can convert data using r gets transformed following pattern:
ab=1 cd=2 ef=3   so vector converted to:
data=[1,1,1,2,2,2,3,3]      
another option match
match(data, unique(data)) #[1] 1 1 1 2 2 2 3 3   or in place of unique(data), can specify vector of elements match.
match(data, c('ab', 'cd', 'ef'))      
Comments
Post a Comment