[R] Convert csv to xpt file in R?
Nordlund, Dan (DSHS/RDA)
NordlDJ at dshs.wa.gov
Thu May 7 17:51:52 CEST 2015
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Santosh
> Sent: Wednesday, May 06, 2015 8:04 PM
> To: r-help
> Subject: [R] Convert csv to xpt file in R?
> Dear Rxperts..
> Was wondering if there is a way in R to read a csv file and generate an
> file? For some reason the function write.xport() does not seem to work
> i get the following error...
> "error in label.data.frame(df,default=""): length of default same as x
> A sample dataframe is given below
> xg2 <- data.frame(aa=runif(10),bb=sample(runif(100),10))
> SASformat(xg2$aa) <- 'Numeric2'
> SASformat(xg2$bb) <- 'Numeric2'
> label(xg2$aa) <- "test aa"
> label(xg2$bb) <- "test bb"
> label(xg2) <- "testa"
> SAStype(xg2) <- "TestXge"
> Error in label.data.frame(df, default = "") :
> length of default must same as x
> Any suggestions/tips are welcome..
> Thanks and regards
The code above runs without error and produces an xport file on my Win7 64-bit system running R-3.2.0. You haven't told us anything about your OS, version of R, and packages loaded. Have you tried running the code from a fresh start of R after only loading the SASxport package?
Daniel J. Nordlund
Research and Data Analysis Division
Services & Enterprise Support Administration
Washington State Department of Social and Health Services
More information about the R-help