我有一个csv文件
标题
的位置Id,Name,State
Data.csv
Id,Name,State
23,Fred,California
56,Sam,Texas
78,Renee,Washington
56,Walter,California
期望的输出
Id,Name,State
56,Sam,Texas
78,Renee,Washington
我已将信息读作
record <- read.csv("Data.csv",header=TRUE)
State <- record$State
我想删除包含“California”的所有行作为“State”值。
R的新手。感谢任何帮助。
答案 0 :(得分:1)
如果您将csv加载到名为df
的数据框中:
df[df$State != "California", ]
您可能需要查看此参考卡:http://cran.r-project.org/doc/contrib/Short-refcard.pdf
修改的
关于您的更新:
record <- read.table(sep=",", header=T, text="
Id,Name,State
23,Fred,California
56,Sam,Texas
78,Renee,Washington
56,Walter,California")
State <- record$State
record[record$State != "California", ]
# Id Name State
# 2 56 Sam Texas
# 3 78 Renee Washington
State[State != "California"]
# [1] Texas Washington
# Levels: California Texas Washington
record[State != "California", ]
# Id Name State
# 2 56 Sam Texas
# 3 78 Renee Washington