I have a dataframe such as this one:
d <- data.frame(cbind(x=1, y=1:10, z=c(\"apple\",\"pear\",\"banana\",\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\"
Here's your problem:
> grep("K",c("apple","pear","banana","A","B","C","D","E","F","G"))
integer(0)
Try grepl() instead:
d[!grepl("K",d$z),]
This works because the negated logical vector has an entry for every row:
> grepl("K",d$z)
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
> !grepl("K",d$z)
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE