powered by
This utility function will recode values from an original character or factor vector with new values.
character
factor
recode(x, from, to, to.class = NULL)
a vector with same length of x with recoded values.
the vector whose values will be recoded.
the old values in x to be recoded.
the new values.
an 'as.' function representing the desired vector type (i.e. as.character, as.numeric, as.logical, as.numeric).
test <- letters[sample(5, 10, replace=TRUE)] recode(test, from=letters[1:5], to=paste('Letter', letters[1:5]))
Run the code above in your browser using DataLab