0

I'm attempting to subset all rows by names that don't contain the + symbol, but can not figure it out. Consider:

df <- data.frame(Models = c("m1+m2", "m3+m4", "m5"), Values = rep(1:3))
df[,3] <- grepl("+", df[,1])
df

  Models Values   V3
1  m1+m2      1 TRUE
2  m3+m4      2 TRUE
3     m5      3 TRUE

Shouldn't row 3 be FALSE?

lmo
  • 37,904
  • 9
  • 56
  • 69
  • 1
    `grepl("\\+", df[,1])` because `+` is a special character in regex ore `grepl("+", df[,1], fixed=TRUE)` to turn off the regex and match on the literal. – lmo Feb 09 '17 at 20:58
  • That works perfectly. Thanks! Feel free to add as answer and I'll accept. Cheers! – AnscombesGimlet Feb 09 '17 at 21:03

0 Answers0