-2

i.stack.imgur.com/hwans.png

How can I recode the V162034a variable so that I only have the categories for Hillary Clinton and Donald Trump - and set the others as missing values?

Txcxa
  • 1
  • easier to answer the question correctly if you provide the data structure in R not in a screen grab of excel. See here https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – user1317221_G Feb 28 '18 at 18:37
  • 1
    Possible duplicate of [Replacing character values with NA in a data frame](https://stackoverflow.com/questions/3357743/replacing-character-values-with-na-in-a-data-frame) – user1317221_G Feb 28 '18 at 18:38

1 Answers1

1
V162034a[ !(V162034a %in% c("2. Hilary Clinton" ,"1. Donald Trump"))] <- NA

This depends on how the data are structured in R, i.e. if it is a column in a data.frame or not.

user1317221_G
  • 15,087
  • 3
  • 52
  • 78