Reputation: 609
I have the following data set:
df <- data.frame(a = c("T", "F", "T"), b = c("USA", "SIG", "FRA"))
I want to filter out a subset whose a
column value is F
. I tried:
library(dplyr)
library(stringr)
df %>%
filter(str_detect(a, "F"))
But I got this Error in stri_detect_regex(string, pattern, opts_regex = opts(pattern)) : object 'a' not found
.
Can anyone please help and give some explanation?
Upvotes: 3
Views: 4464
Reputation: 1373
Firstly, good job on providing example code to work with, giving the error and proper formatting. Wish I can give you some sort of badge.
Your code is correct. You're not executing the entire block of code, therefore you get that error. You may be running an old version of R/RStudio, because in the recent version, crtl+enter
on the filter
command will execute the whole block of code. On older versions it doesn't behave this way.
Either select the enter code block and run it or have the code on a single line:
df %>%filter(str_detect(a, "F"))
Upvotes: 5