Sunday, 11 August 2013

remove rows containing certain data

remove rows containing certain data

In my data frame the first column is a factor and I want to delete rows
that have a certain value of factorname (when the value is present). I
tried:
df <- df[-grep("factorname",df$parameters),]
Which works well when the targeted factor name is present. However if the
factorname is absent, this command destroys the data frame, leaving it
with 0 rows. So I tried:
df <- df[!apply(df, 1, function(x) {df$parameters == "factorname"}),]
that does not remove the offending lines. How can I test for the presence
of factorname and remove the line if factorname is present?

No comments:

Post a Comment