[R] extracting characters from a string

Bert Gunter gunter.berton at gene.com
Wed Jan 23 19:01:37 CET 2013

1. Study a regular expression tutorial on the web to learn how to do this.

2. ?regex in R summarizes (tersely! -- but clearly) R's regex's.

3. ?grep tells you about R's regular expression manipulation functions.

-- Bert

On Wed, Jan 23, 2013 at 9:38 AM, Biau David <djmbiau at yahoo.fr> wrote:
> Dear All,
> I have a data frame of vectors of publication names such as 'pub':
> pub1 <- c('Brown DK, Santos R, Rome DF, Don Juan X')
> pub2 <- c('Benigni D')
> pub3 <- c('Arstra SD, Van den Hoops DD, lamarque D')
> pub <- rbind(pub1, pub2, pub3)
> I would like to construct a dataframe with only author's last name and each last name in columns and the publication in rows. Basically I want to get rid of the initials (max 2, always before a comma) and spaces surounding last name. I would like to avoid a loop.
> ps: If I could have even a short explanation of the code that extract the values of the character string that would also be great!
> David
>         [[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list
> 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.


Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374

More information about the R-help mailing list