dimanche 15 mars 2020

R: Getting a string from entire dataframe based on pattern

Assuming I have a dataframe containing these details:

Name   Card1    Card2
A      A11234   A24321
B      B11234   B24321
C      C11234   C24321
D      D11234   D24321
E      E11234   E24321

I would like to extract the strings from this dataframe based on pattern "1234" & "4321" in character form. Assuming I extracted the strings to a variable named all_cards, the desired outcome would look like:

> all_cards
 [1] "A11234"           "A24321"            "B11234"          "B24321"        
 [2] "C11234"           "C24321"            "D11234"          "D24321"     
 [3] "E11234"           "E24321"        

> str(all_cards)
 chr [1:10] "A11234" "A24321" "B11234" "B24321" ...

Please advise, thank you in advance!

Aucun commentaire:

Enregistrer un commentaire