Multiple na.strings in read.table() function in R

一曲冷凌霜 提交于 2019-11-30 17:34:01

问题


I have a square table and it has two na.strings (e.g. "A" and "B") that I need to turn into NA. So far I can turn either one of those into NA but not both. How should I do this? Can I use a function in that argument? If yes, what function should I use? I tried like (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")

回答1:


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

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

From the helpfile:

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



来源:https://stackoverflow.com/questions/16980646/multiple-na-strings-in-read-table-function-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!