将数据集作为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
替换w
和x
所标识的索引中的观察值,即
Pct.of.faculty.with.PhDs[w] = NA
应该在output.csv中为观察索引NA
输出[82]
,而不是原始的112