我有一个方 table ,它有两个 na.strings(例如“A”和“B”),我需要把它们变成 NA。到目前为止,我可以将其中任何一个变成 NA,但不能同时将两者都变成。我该怎么做?我可以在该参数中使用函数吗?如果是,我应该使用什么功能?我试过 ( na.strings = "A" | "B"
) 和 ( na.strings = "A | B"
) 但它不起作用。我的代码如下:
loadfile<-read.table("test.csv", header=T, sep=",", na.strings="A | B")
最佳答案
na.strings
接受一个字符向量,所以...
loadfile <- read.table( "test.csv" , header = TRUE ,
sep="," ,
na.strings = c("A" , "B" ) )
从帮助文件:
na.strings: a character vector of strings which are to be interpreted as NA values
关于r - R 中 read.table() 函数中的多个 na.strings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16980646/