r - changing factors to numeric - how to cope with unavailable values -


i have big data set questionary. importing spss r (using spss's stata-output) gave me answer each question factor.

a question has answers 1 10. however, there lot of missing values. r recoginzes them aswell.

however, i'd calculations - example want calculate mean of answer (not statistics, know, never mind).

so have make recode factors numerics. did as.numeric().

however, have missing values encoded 11 14. of course can't calculate mean this.

what proper way recode factors numerics , tell r set value bigger 10 na?

example: fish?

    not @                   | don't know  no answer  don't tell r:  1   2   3   4   5   6   7   8   9   10 |     11          12         13 

if don't need missing values, i'd like:

a[a>10] <- na 

then, can use:

mean(a, na.rm=true) 

alternately, if want work around missing values, can use:

mean(a[a<=10]) 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -