Re: [R] matching subvectors in vector sets

2009-04-18 Thread David Winsemius
xlist <-list() for (i in 2:length(x.s)){ x.seq <- embed(length(x.s):1, i) xlist[[i]] <- table(apply(x.seq, 1, function(z){ paste(x.s[z], collapse=":") })) } xlist -- David Winsemius On Apr 18, 2009, at 11:46 AM, Albert Vilella wrote: that works very well. how d

Re: [R] matching subvectors in vector sets

2009-04-18 Thread Albert Vilella
that works very well. how do I store the results into a variable instead of doing a print? On Fri, Apr 17, 2009 at 5:51 PM, jim holtman wrote: > How about this: > > > x <- "A00096:A00096:A00096:A00096:A02178:A02178:A07776" > > x.s <- unlist(strsplit(x, ":")) > > for (i in 2:length(x.s)){ > +

Re: [R] matching subvectors in vector sets

2009-04-17 Thread jim holtman
How about this: > x <- "A00096:A00096:A00096:A00096:A02178:A02178:A07776" > x.s <- unlist(strsplit(x, ":")) > for (i in 2:length(x.s)){ + x.seq <- embed(length(x.s):1, i) + print(table(apply(x.seq, 1, function(z){ + paste(x.s[z], collapse=":") + }))) + } A00096:A00096 A00096:A

Re: [R] matching subvectors in vector sets

2009-04-17 Thread Albert Vilella
Starting by the first entry: A00096:A00096:A00096:A00096:A02178:A02178:A07776 and supposing there aren't any other subvectors identical in the set, the algorithm will slide through the vector, first in pairs, then in trios, then in sets of four, etc, and count the occurrences: A00096:A00096 3 A00