Re: [R] Identifying common prefixes from a vector of words, and delete those prefixes

From: <Richard.Cotton_at_hsl.gov.uk>
Date: Thu, 31 Jul 2008 14:21:55 +0100


> For example, c("dog.is.an.animal", "cat.is.an.animal", "rat.is.an.
> animal"). How can I identify the common prefix is ".is.an.animal"
> and delete it to give c("dog", "cat", "rat") ?
foo <- c("dog.is.an.animal", "cat.is.an.animal", "rat.is.an.animal") sub(".is.an.animal", "", foo)

Being pedantic, ".is.an.animal" is a suffix not a prefix since it comes afterwards.

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION: This message contains privileged and confidential inform...{{dropped:20}}

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. Received on Thu 31 Jul 2008 - 13:30:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 31 Jul 2008 - 14:33:03 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive