Last active
August 29, 2015 14:14
-
-
Save dickoa/42c04feeac21b46eb2e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(foreign) | |
set.seed(1) | |
df <- as.data.frame(matrix(rnorm(1e8), ncol = 10)) | |
write.csv(df, "/tmp/test.csv", row.names = FALSE) | |
write.dta(df, "/tmp/test.dta") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET DATA | |
/TYPE=TXT | |
/FILE="/tmp/test.csv" | |
/IMPORTCASES=ALL | |
/ARRANGEMENT=DELIMITED | |
/DELCASE=LINE | |
/FIRSTCASE=2 | |
/DELIMITERS="," | |
/VARIABLES= | |
V1 F20.14 | |
V2 F20.14 | |
V3 F20.14 | |
V4 F20.14 | |
V5 F20.14 | |
V6 F20.14 | |
V7 F20.14 | |
V8 F20.14 | |
V9 F20.14 | |
V10 F20.14. | |
SAVE OUTFILE="/tmp/test.sav". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(foreign) | |
library(haven) | |
library(rbenchmark) | |
sav_file <- "/tmp/test.sav" | |
dta_file <- "/tmp/test.dta" | |
read_sav_foreign <- function(file) | |
read.spss(file, to.data.frame = TRUE) | |
read_sav_haven <- function(file) | |
read_sav(file) | |
read_dta_foreign <- function(file) | |
read.dta(file) | |
read_dta_haven <- function(file) | |
read_dta(file) | |
benchmark(read_sav_foreign(sav_file), | |
read_sav_haven(sav_file), | |
replications = 10, | |
order = "elapsed", | |
columns = c("test", "replications", "elapsed", "relative")) | |
## test replications elapsed relative | |
## 1 read_sav_foreign(sav_file) 10 21.760 1.000 | |
## 2 read_sav_haven(sav_file) 10 73.854 3.394 | |
benchmark(read_dta_foreign(dta_file), | |
read_dta_haven(dta_file), | |
replications = 10, | |
order = "elapsed", | |
columns = c("test", "replications", "elapsed", "relative")) | |
## test replications elapsed relative | |
## 1 read_dta_foreign(dta_file) 10 63.895 1.00 | |
## 2 read_dta_haven(dta_file) 10 152.705 2.39 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment