R中read.table()函数中的多个na.strings [英] Multiple na.strings in read.table() function in R

查看:802
本文介绍了R中read.table()函数中的多个na.strings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方桌,它有两个na.strings(例如"A"和"B"),我需要将其转换为NA.到目前为止,我可以将其中任何一个转换为NA,但不能同时将两者转换为NA.我应该怎么做?我可以在该参数中使用函数吗?如果是,我应该使用什么功能?我试过像(na.strings = "A" | "B")和(na.strings = "A | B")一样,但是它不起作用.我的代码如下:

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")

推荐答案

na.strings采用字符向量,所以...

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

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

从帮助文件:

na.strings:将被解释为NA值的字符串的字符向量

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

这篇关于R中read.table()函数中的多个na.strings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆