Read CVS file with tagged values for missing data

Hi everybody,

I have a csv file where the missing values are denoted by either '.A' or '.B' (as with SAS dataset). I can read this file with read_csv function with the option na=c('.A','.B').

library(readr)
test = data.frame(
  x=1:5,
  y=c(1:4,'.A'),
  z=c('.B',2:5)
)
test
#>   x  y  z
#> 1 1  1 .B
#> 2 2  2  2
#> 3 3  3  3
#> 4 4  4  4
#> 5 5 .A  5

write_csv(test, 'test.csv') # Creating a csv file on local drive

test2=read_csv('test.csv', na=c('.A','.B'))
#> 
#> -- Column specification --------------------------------------------------------
#> cols(
#>   x = col_double(),
#>   y = col_double(),
#>   z = col_double()
#> )

test2
#> # A tibble: 5 x 3
#>       x     y     z
#>   <dbl> <dbl> <dbl>
#> 1     1     1    NA
#> 2     2     2     2
#> 3     3     3     3
#> 4     4     4     4
#> 5     5    NA     5

Created on 2021-06-24 by the reprex package (v2.0.0)

However, I want to know if there is a way I can read the file and keep the notations '.A' and '.B' for missing values.

Thanks in advance for any of your help.

Ha

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.