[R] recoding responses in a numeric variable

Licia Biotti biottilicia at gmail.com
Sat Jan 7 23:53:35 CET 2017


Hello,

I am working with a dataset in R studio, and I have created a numeric
variable which I have called fear by using a factor variable (called vn35).
Here is the piece of code:
fear<-gles_reduced$vn35
levels(fear)
table(fear, as.numeric(fear), exclude=NULL)

Then I have coded the levels "don't know" and "not specified" as NA
fear[fear=="not specified"]<-NA
fear[fear=="don't know"]<-NA

This is how the table looks like:

fear                          3    4    5    6    7 <NA>
  no entry                 0    0    0    0    0    0
  don't know             0    0    0    0    0    0
  a lot of fear           412    0    0    0    0    0
  big fear                   0  883    0    0    0    0
  medium fear           0    0  1350    0    0    0
  little fear                 0    0    0  920    0    0
  no fear at all           0    0    0    0  305    0
  <NA>                      0    0    0    0    0    41

I would like to code the remaining answers (a lot of fear, big fear, medium
fear, little fear and no fear at all) with values from 0 to 4 (so that
greater values indicate great concern)
I tried this piece of code:
fear[fear=="big fear"]<-1
But it is not working,
could you please help me?
Thanks,

	[[alternative HTML version deleted]]



More information about the R-help mailing list