[R] how to get all strings in a data frame that start with a particular string

Michael Dewey ||@t@ @end|ng |rom dewey@myzen@co@uk
Fri Apr 10 18:43:01 CEST 2020


Dear Ana

Would it not be possible to use grep instead of grepl and get the values 
using the value = TRUE parameter?

Michael

On 10/04/2020 17:15, Ana Marija wrote:
> Hello,
> 
> Hello,
> 
> I have a data frame (tot) with about 2000 columns. How can I extract
> from it all strings that start with E14?
> 
> I tried this:
> e14 <- sapply(tot, function(x) grepl("^E14", x))
> 
> but this returns me just TRUE and FALSE vector, how do I get actual
> strings that start with E14?
> 
> 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.
> 

-- 
Michael
http://www.dewey.myzen.co.uk/home.html



More information about the R-help mailing list