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

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?



Solution 1:[1]

To convert the empty strings to missing you can do:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 deschen