Filtering rows that start with a symbol "*"

Is there a way to filter rows that start with "*" or "#" for instance?

x <- c("*aa", "#aa", "aa")
y <- c(10, 20, 30)
df = data.frame(x, y)

I tried the following codes but I', getting "[1] x y
<0 rows> (or 0-length row.names)"

df %>% filter(!grepl("^*", x))

df %>% slice(grep("^*", x, invert = TRUE))

Thanks

Hi, you want to escape your symbols as such:

df %>% filter(!grepl("^\\#", x))

Hope that helps.

2 Likes

Thank you @headsortails; this is exactly what I was looking for!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.