Reputation: 613
I have a csv file as
Where the headers are
Id,Name,State
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.
Upvotes: 1
Views: 1315
Reputation: 54237
In case you loaded the csv into a data frame called df
:
df[df$State != "California", ]
You might want to check out this ref card: 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
Upvotes: 1