The set of na.strings in read.table () in R

I have a square table and it has two na.strings (for example, "A" and "B") that I need to turn into NA. So far, I can turn either of them into NA, but not both. How can I do it? Can I use a function in this argument? If so, which function should I use? I tried ( na.strings = "A" | "B" ) and ( na.strings = "A | B" ), but it does not work. My code is as follows:

 loadfile<-read.table("test.csv", header=T, sep=",", na.strings="A | B") 
+4
source share
1 answer

na.strings accepts a character vector, so ...

 loadfile <- read.table( "test.csv" , header = TRUE , sep="," , na.strings = c("A" , "B" ) ) 

From the help file:

na.strings: character vector of strings to be interpreted as NA values

+19
source

Source: https://habr.com/ru/post/1485008/


All Articles