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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -