R sqldf - match.fun (asfn) 'c ("as.labelled", "as.integer")' is not a function, symbol or symbol
Totally new to R, just spent a couple of hours playing and thought I would have a game with some NHANES datasets for example. ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/nhanes/2003-2004/
So grabbed a couple and after playing with merge(bmx_c, demo_c)
and a quick google I thought a library sqldf
would be a more efficient way to combine / extract only a few columns from files to play, but I "You have a problem".
Error in match.fun(asfn) :
'c("as.labelled", "as.integer")' is not a function, character or symbol**
NHANES files are in SAS format, so I had to:
install.packages("Hmisc")
install.packages("sqldf")
library(Hmisc)
library(sqldf)
demo_c <- sasxport.get("DEMO_C.XPT")
bmx_c <- sasxport.get("BMX_C.XPT")
is.data.frame(demo_c)
[1] TRUE
sqldf("select seqn from demo_c")
Error in match.fun(asfn) :
'c("as.labelled", "as.integer")' is not a function, character or symbol
>
summary(demo_c$seqn)
Min. 1st Qu. Median Mean 3rd Qu. Max.
21000 23540 26070 26070 28600 31130
>
I assume some type conversion is required, but I don't know the intricacies of R.
source to share
sqldf does not support the Hmisc generated column class "labelled"
. All columns appear to be integer or numeric, so convert the columns to numeric first:
demo_c[] <- lapply(demo_c, as.numeric)
sqldf("select seqn from demo_c")
You can convert integers to integer if you like:
isInt <- sapply(demo_c, inherits, "integer")
demo_c[isInt] <- lapply(demo_c[isInt], as.integer)
demo_c[!isInt] <- lapply(demo_c[!isInt], as.numeric)
source to share