gpt4 book ai didi

r - R 中 read.table() 函数中的多个 na.strings

转载 作者:行者123 更新时间:2023-12-03 15:08:21 26 4
gpt4 key购买 nike

我有一个方 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com