且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将空白单元格更改为“NA"

更新时间:2023-02-13 16:48:56

我假设您在谈论第 5 行列性".可能的情况是,在 data2.csv 文件中,单元格包含一个空格,因此 R 不会将其视为空.

I'm assuming you are talking about row 5 column "sex." It could be the case that in the data2.csv file, the cell contains a space and hence is not considered empty by R.

另外,我注意到在第 5 行axles"和door"中,从 data2.csv 读取的原始值是字符串NA".您可能也想将它们视为 na.strings .为此,

Also, I noticed that in row 5 columns "axles" and "door", the original values read from data2.csv are string "NA". You probably want to treat those as na.strings as well. To do this,

dat2 <- read.csv("data2.csv", header=T, na.strings=c("","NA"))

我下载了你的 data2.csv.是的,第 5 行性别"列中有一个空格.所以你想要

I downloaded your data2.csv. Yes, there is a space in row 5 column "sex". So you want

na.strings=c(""," ","NA")