remove rows containing certain data

dataframe, r

Solution

You could use:

df[ which( ! df$parameter %in% "factorname") , ]

(Used `%in%` since it would generalize better to multiple exclusion criteria.) Also possible:

df[ !grepl("factorname", df$parameter) , ]

Problem

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?

Original source