Total newbie to R, have just spent a couple of hours playing and thought I'd have a play with some of the NHANES datasets e.g. ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/nhanes/2003-2004/
So grabbed a couple and after a play with merge(bmx_c, demo_c) and a quick Google I thought the sqldf library would be a more efficient way to merge / extract just a few columns from the files, to play with, but I've hit a problem.
Error in match.fun(asfn) : 
  'c("as.labelled", "as.integer")' is not a function, character or symbol**
The 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'm guessing some type conversion is required, but I don't know the subtleties of R.
sqldf does not support the "labelled" column class produced by Hmisc.  All the columns seem 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 could convert the integer ones to integer if you prefer:
isInt <- sapply(demo_c, inherits, "integer")
demo_c[isInt] <- lapply(demo_c[isInt], as.integer)    
demo_c[!isInt] <- lapply(demo_c[!isInt], as.numeric)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With