user_na = FALSE does not make all empty rows NA - only for some columns when reading using read_sav

100 Views Asked by At

I use

df <- read_sav("data/file.sav", user_na = FALSE)

But the data does not look like expected

col1   col2
1      Onestreet
2      Twostreet
NA
4    
5

How come rows 3-5 not become NA in col2?

1

There are 1 best solutions below

2
deschen On

To convert the empty strings to missing you can do:

library(dplyr)
df %>%
  mutate(col2 = if_else(col2 == '', NA_character_, col2))