[R] Identifying common prefixes from a vector of words, and delete those prefixes
Richard.Cotton at hsl.gov.uk
Richard.Cotton at hsl.gov.uk
Thu Jul 31 15:21:55 CEST 2008
> 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}}
More information about the R-help
mailing list