samedi 7 novembre 2015

Searching for patterns and only getting the patterns as output (R)?

I'm pretty new to R and I would appreciate any answer :)

I want to search for a pattern within elements of a vector and only return that pattern.

let's say my vector is ("7BC-137", "A56_asdf", "M33_T99")

I want the output to be of the pattern [0-9][A-Z][A-Z]. And only the first occurence of it.

The vector should then be ("7BC", "A56", "M33")

grep("[A-Z][0-9][0-9]", nameofvector) returns the whole entry and I don't know how to return only the found pattern.

Thank you very much in advance!

Aucun commentaire:

Enregistrer un commentaire