Re: [R] Finding overlaps in vector

2007-12-22 Thread Johannes Graumann
Enlightening. Thanks. Joh Gabor Grothendieck wrote: > If you want indexes, i.e. 1, 2, 3, ... instead of the values in v you > can still use split -- just split on seq_along(v) instead of v (or if > v had names you might want to split along names(v)): > > split(seq_along(v), ct) > > and if you

Re: [R] Finding overlaps in vector

2007-12-22 Thread Gabor Grothendieck
If you want indexes, i.e. 1, 2, 3, ... instead of the values in v you can still use split -- just split on seq_along(v) instead of v (or if v had names you might want to split along names(v)): split(seq_along(v), ct) and if you only want to retain groups with 2+ elements then you can just Filter

Re: [R] Finding overlaps in vector

2007-12-22 Thread David Winsemius
Johannes Graumann <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > But cutree does away with the indexes from the original input, which > rect.hclust retains. > I will have no other choice and match that input with the 'values' > contained in the clusters ... If you want to retain the ori

Re: [R] Finding overlaps in vector

2007-12-22 Thread Johannes Graumann
Here's what I finally came up with. Thanks for your help! Joh MQUSpotOverlapClusters <- function( Series,# Vector of data to be evaluated distance=0.5,# Maximum distance of clustered data points minSize=2# Minimum size of clusters returned ){

Re: [R] Finding overlaps in vector

2007-12-22 Thread Johannes Graumann
But cutree does away with the indexes from the original input, which rect.hclust retains. I will have no other choice and match that input with the 'values' contained in the clusters ... Joh Gabor Grothendieck wrote: > If we don't need any plotting we don't really need rect.hclust at > all. Sp

Re: [R] Finding overlaps in vector

2007-12-21 Thread Gabor Grothendieck
If we don't need any plotting we don't really need rect.hclust at all. Split the output of cutree, instead. Continuing from the prior code: > for(el in split(unname(vv), names(vv))) print(el) [1] 0.00 0.45 [1] 1 [1] 2 [1] 3.00 3.25 3.33 3.75 4.10 [1] 5 [1] 6.00 6.45 [1] 7.0 7.1 [1] 8 On Dec 21,

Re: [R] Finding overlaps in vector

2007-12-21 Thread Johannes Graumann
Hm, hm, rect.hclust doesn't accept "plot=FALSE" and cutree doesn't retain the indexes of membership ... anyway short of ripping out the guts of rect.hclust to achieve the same result without an active graphics device? Joh >> # cluster and plot >> hc <- hclust(dist(v), method = "single") >> plot(h

Re: [R] Finding overlaps in vector

2007-12-21 Thread Johannes Graumann
Jim, Although I can't find the post this code stems from, I had come across it on my prowling the NG. It's not the one you had shared with me to eliminate overlaps (and which I referenced below: http://tolstoy.newcastle.edu.au/R/e2/help/07/07/21286.html). That particular solution you had come up w

Re: [R] Finding overlaps in vector

2007-12-21 Thread Johannes Graumann
Thank you very much for this elegant solution to the problem. The reason I still hope for an extension of Jim's code (not the one re responded with in this thread, but the one I actually reference) is that windows of overlap can be asymetric with that: one can check e.g. whether values overlap give

Re: [R] Finding overlaps in vector

2007-12-21 Thread Charles C. Berry
On Fri, 21 Dec 2007, Johannes Graumann wrote: > > > Dear all, > > I'm trying to solve the problem, of how to find clusters of values in a > vector that are closer than a given value. Illustrated this might look as > follows: > > vector <- c(0,0.45,1,2,3,3.25,3.33,3.75,4.1,5,6,6.45,7,7.1,8) > > Wh

Re: [R] Finding overlaps in vector

2007-12-21 Thread Gabor Grothendieck
This may not be as direct as Jim's in terms of specifying granularity but will uses conventional hierarchical clustering to create the clusters and also draws a nice dendrogram for you. I have split the dendrogram at a height of 0.5 to define the clusters but you can change that to whatever granu

Re: [R] Finding overlaps in vector

2007-12-21 Thread jim holtman
Here is a modification of the algorithm to use a specified value for the overlap: > vector <- c(0,0.45,1,2,3,3.25,3.33,3.75,4.1,5,6,6.45,7,7.1,8) > # following add 0.5 as the overlap detection -- can be changed > x <- rbind(cbind(value=vector, oper=1, id=seq_along(vector)), +cbind(valu

[R] Finding overlaps in vector

2007-12-21 Thread Johannes Graumann
Dear all, I'm trying to solve the problem, of how to find clusters of values in a vector that are closer than a given value. Illustrated this might look as follows: vector <- c(0,0.45,1,2,3,3.25,3.33,3.75,4.1,5,6,6.45,7,7.1,8) When using '0.5' as the proximity requirement, the following groups