[R] Recoding lists of categories of a variable

MACDOUGALL Margaret Margaret.MacDougall at ed.ac.uk
Mon Oct 10 16:56:18 CEST 2016


Hello

The R code
mydata$newvar[oldvar = "topic1"] <- "parenttopic"

is intended to recode the category 'topic 1' of the old  varaible 'oldvar' a new category label 'parenttopic' by defining the new variable 'newvar'.

Is there a convenient way to edit this code to allow me to recode a list of categories 'topic 1', 'topic 9' and 'topic 14', say, of the the old variable 'oldvar' as 'parenttopic' by means of the new variable 'newvar', while also mapping system missing values to system missing values?

Thanks in advance

Best wishes
Margaret

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20161010/4887f76b/attachment.pl>


More information about the R-help mailing list