0
votes

I'm trying to filter email accounts that contain the domain "gmail"

here's how it goes:

library(dplyr)
GMAIL<- read.csv(file.choose())
GMAIL <- data.frame(lapply(GMAIL, as.character), stringsAsFactors=FALSE)
GMAIL2<-GMAIL
GMAIL2 %>%
filter(Email, contains("gmail"))

the error i get is: Error in filter_impl(.data, quo) : Evaluation error: object 'Email' not found.

And my Data "GMAIL" only has one column named "Email"

I would also like to make a new dataset with the filtering result, how can I also accomplish this?

Thx in advance

2
Hi, I also tryed the following >library(stringr) >GMAIL2 %>% filter(str_detect(Email, "gmail")) and the same error appears: -Error in filter_impl(.data, quo) : Evaluation error: object 'Email' not found. - Marchelo
contains is not a verb used within filter. Perhaps you mean GMAIL2 %>% filter(grepl("gmail", Email))? I suggest some of the tutorials/docs at dplyr.tidyverse.org to fine-tune where you use column-finding verbs like contains and what can be used within filter. - r2evans
please always post reproducible questions no one else on the internet has access to whatever file you pick after file.choose() >>> whatever.csv - Nate
hi nate, ok i'll do my best on the next query! - Marchelo

2 Answers

1
votes

To filter and save the results to a new df:

filtered_gmail <- GMAIL2 %>%
  filter(grepl("gmail", Email))
0
votes

You can use select instead of filter

library(dplyr)
GMAIL<- read.csv(file.choose())
GMAIL <- data.frame(lapply(GMAIL, as.character), stringsAsFactors=FALSE)
GMAIL2<-GMAIL
GMAIL2 %>%
select(contains("gmail"))