coerce labelled variables to numeric after recoding
<p>Is there a simpler way in the haven or labelled packages to turn labelled variables into numeric variables? </p>

<p>The following code illustrates my problem.  After important from an sav file, every variable is a labelled variable.  Some are, originally, numeric variables, with 98 and 99 as missing values. So I have to recode those to set to NA, but then I have to coerce the recoded variable to numeric with as.numeric()</p>

<p>Is there a simpler way to do this?</p>

<pre><code>#Load libraries
library(devtools)
library(dplyr)
library(car)
#Install package with data
install_github('sjkiss/LSIRM')
#Load library
library(LSIRM)
#Loda dataset
data(ces)
#show variable of interest
table(ces$PES15_74)
#Get variable labels
variable_labels&lt;-lapply(ces, function(x) attr(x, 'label'))
#Get value labels
value_labels&lt;-lapply(ces, function(x) attr(x, 'labels'))
#Show class of variable of interest
class(ces$PES15_74)
#show variable and value labels
ces$PES15_74 
attr(ces$PES15_74, 'labels') #Note 98 and 99 should be missing values 
#Show mean
mean(ces$PES15_74, na.rm=T)
#Recode out missing values
ces$tv&lt;-recode(ces$PES15_74, "98:99=NA")
#Show class
class(ces$tv)
#Try with as.factor.result=F
ces$tv2&lt;-recode(ces$PES15_74, "98:99=NA", as.factor.result=F)
#show class
class(ces$tv2)
#coerce to numeric
ces$tv&lt;-as.numeric(ces$tv)
#show mean after coercion
mean(ces$tv, na.rm=T)
#show mean uncoerced
mean(ces$PES15_74, na.rm=T)
</code></pre>