[英]How to remove all rows based on a particular column in R?
I have a csv file as 我有一个CSV文件
Where the headers are 标头在哪里
Id,Name,State
Data.csv Data.csv
Id,Name,State
23,Fred,California
56,Sam,Texas
78,Renee,Washington
56,Walter,California
Desired output 所需的输出
Id,Name,State
56,Sam,Texas
78,Renee,Washington
I have read the information as 我已将信息阅读为
record <- read.csv("Data.csv",header=TRUE)
State <- record$State
I want to remove all rows containing "California" as the "State" value. 我想删除所有包含“加利福尼亚”作为“州”值的行。
New to R. Any help is appreciated. R的新手。任何帮助都将受到赞赏。
In case you loaded the csv into a data frame called df
: 如果您将csv加载到名为df
的数据帧中:
df[df$State != "California", ]
You might want to check out this ref card: http://cran.r-project.org/doc/contrib/Short-refcard.pdf 您可能要签出此参考卡: http : //cran.r-project.org/doc/contrib/Short-refcard.pdf
Edit 编辑
With regards to your update: 关于您的更新:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.