[R] how to extract strings in any column and in any row that start with

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Fri May 15 19:13:50 CEST 2020


Read about regular expressions... they are extremely useful.

df1 <- tot %>% filter_all(any_vars(grepl( '^E10', .)))

It is bad form not to put spaces around the <- assignment.


On May 15, 2020 10:00:04 AM PDT, Ana Marija <sokovic.anamarija using gmail.com> wrote:
>Hello,
>
>I have a data frame:
>
>> dim(tot)
>[1] 502536   1093
>
>How would I extract from it all strings that start with E10?
>
>I know how to extract all rows that contain with E10
>df0<-tot %>% filter_all(any_vars(. %in% c('E10')))
>> dim(df0)
>[1] 5105 1093
>
>but I just need a vector of strings that start with E10...
>it would look something like this:
>
>[1] "E102" "E109" "E108" "E103" "E104" "E105" "E101" "E106" "E107"
>
>Thanks
>Ana
>
>______________________________________________
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list