Leonhard Euler
Leonhard Euler

Reputation: 281

Read only specific columns of SPSS .sav files into R

I'm importing some SPSS .sav files into R.

They are huge, thousands of rows, thousands of variables. But I only need 3 or 4 key variables from the data.

Is there any way to let an import function (currently using read_sav() from the "haven" package) what variables these are to cut down on upload time?

Cheers

Upvotes: 2

Views: 672

Answers (1)

Hieu Nguyen
Hieu Nguyen

Reputation: 609

You can use the col_select argument of haven::read_sav function

library(haven)
tmp <- tempfile(fileext = ".sav")
write_sav(mtcars, tmp)

all_data <- read_sav(tmp)
someCol_data <- read_sav(tmp, col_select = c("hp", "mpg"))

Upvotes: 3

Related Questions