Re: [R] Finding the common portion of strings

2011-03-25 Thread Gabor Grothendieck
On Fri, Mar 25, 2011 at 4:47 PM, Gabor Grothendieck wrote: > On Fri, Mar 25, 2011 at 1:27 PM, Dennis Fisher wrote: >> Colleagues >> >> R: 2.12.2 >> OS X >> >> I have a set of text objects in the form (I am showing 3 of what is more >> likely to be 20 or so): >>        OBJECTS <- c("abcSOMETHINGC

Re: [R] Finding the common portion of strings

2011-03-25 Thread Gabor Grothendieck
On Fri, Mar 25, 2011 at 1:27 PM, Dennis Fisher wrote: > Colleagues > > R: 2.12.2 > OS X > > I have a set of text objects in the form (I am showing 3 of what is more > likely to be 20 or so): >        OBJECTS <- c("abcSOMETHINGCOMMONegf", "xSOMETHINGCOMMONyz", > "SOMETHINGCOMMONnme") > > As you c

Re: [R] Finding the common portion of strings

2011-03-25 Thread Bert Gunter
Define: "common string of characters" for: x <- "abcdghi" y <- "abcghi" z <- "ghiabc" u <- "abghabc" -- Bert On Fri, Mar 25, 2011 at 10:34 AM, Henrique Dallazuanna wrote: > Try this: > > intersect2 <- function (x, y) > { >    y <- as.vector(y) >    y[match(as.vector(x), y, 0L)] > } > > paste(R

Re: [R] Finding the common portion of strings

2011-03-25 Thread Henrique Dallazuanna
Try this: intersect2 <- function (x, y) { y <- as.vector(y) y[match(as.vector(x), y, 0L)] } paste(Reduce(intersect2, strsplit(OBJECTS, NULL)), collapse = '') On Fri, Mar 25, 2011 at 2:27 PM, Dennis Fisher wrote: > Colleagues > > R: 2.12.2 > OS X > > I have a set of text objects in the f

[R] Finding the common portion of strings

2011-03-25 Thread Dennis Fisher
Colleagues R: 2.12.2 OS X I have a set of text objects in the form (I am showing 3 of what is more likely to be 20 or so): OBJECTS <- c("abcSOMETHINGCOMMONegf", "xSOMETHINGCOMMONyz", "SOMETHINGCOMMONnme") As you can see, all contain "SOMETHINGCOMMON" and the position varies. But, I d