There MUST be a better way but this will work. 

x <- c("dog.is.an.animal", "cat.is.an.animal", "rat.is.an.animal")
bb <- strsplit(x, "\\.")
myfun <- function(m) m[1]
animals  <- unlist(lapply(bb, myfun))
animals




--- On Thu, 7/31/08, Daren Tan <[EMAIL PROTECTED]> wrote:

> From: Daren Tan <[EMAIL PROTECTED]>
> Subject: [R] Identifying common prefixes from a vector of words, and delete 
> those prefixes
> To: [EMAIL PROTECTED]
> Received: Thursday, July 31, 2008, 7:11 AM
> 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") ?
>  
> Thanks
> _________________________________________________________________
> 
> 
>       [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help@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.


      __________________________________________________________________
[[elided Yahoo spam]]

______________________________________________
R-help@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.

Reply via email to