NA已添加到数据框中,未显示在输出.csv

时间:2019-11-04 03:08:27

标签: csv dataframe na

将数据集作为df导入到R中。进行一些更改,即进行某些值NA现在尝试将更改后的df写为.csv,但更改未显示在.csv输出中


usnews_colleges1 <- read.csv(file = "/user1/usnews_colleges.csv", header = T, sep = ",")
attach(usnews_colleges1)

#Percentage of faculty with PhDs
w <- which(Pct.of.faculty.with.PhDs > 100)
w
#Change percentages > 100 to NA
Pct.of.faculty.with.PhDs[w] = NA

 Student/Faculty Ratio
x <- which(Student.faculty.ratio > 50)
x
#Change ratios > 50 to NA
Student.faculty.ratio[x] = NA

write.csv(usnews_colleges1, "/uset1/usnews_collegesEdit.csv", row.names = F)


输出文件usnews_collegesEdit.csv应该用NA替换wx所标识的索引中的观察值,即 Pct.of.faculty.with.PhDs[w] = NA应该在output.csv中为观察索引NA输出[82],而不是原始的112

0 个答案:

没有答案