Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trimming a List Based On Partial Matches

I have a list like this :

> my_list

  [1] "https://pizza.ca/login/"                                                                                            
  [2] "https://chocolate.ca/memberships/levels-page/"                                                                          
  [3] "https://www.pizza123.ca/wp-content/"                     
  [4] "https://twitter.com/ddcus"                                                                                                           
  [5] "https://www.facebook.com/"  

I only want to keep elements in this list that contain the term "pizza".

I tried the following code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

new_list = grep("pizza", my_list)

But this is not working. The final answer should look like this:

 [1] "https://pizza.ca/login/"                                                                                                                                                                   
 [2] "https://www.pizza123.ca/wp-content/" 

Any idea how to do this?

Thanks!

>Solution :

new_list <- my_list[grep("pizza", my_list)]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading