maybe you could try something along these lines:
x - c(1, 3, 2, 5, 11)
thr - 3
###
ind - t(combn(x, 2))
unique(c(ind[abs(ind[, 1] - ind[, 2]) = thr, ]))
I hope it helps.
Best,
Dimitris
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of
Dear Bart,
hclust might be useful for this as well:
dat = c(1,20,2,21)
hc = hclust(dist(dat))
thresh = 2
ct = cutree(hc, h=thresh)
clusteredNumbers = split(dat, ct)
firstOne = dat[!duplicated(ct)]
clusteredNumbers
$`1`
[1] 1 2
$`2`
[1] 20 21
firstOne
[1] 1 20
).
Thanks to all for you input, it was a great help!!
Bart Joosen
- Original Message -
From: Wolfgang Huber [EMAIL PROTECTED]
To: Bart Joosen [EMAIL PROTECTED]
Cc: r-help@stat.math.ethz.ch
Sent: Sunday, February 11, 2007 4:09 PM
Subject: Re: [R] Near function?
Dear Bart,
hclust
Bart Joosen bartjoosen at hotmail.com writes:
Hi,
I have an integer which is extracted from a dataframe, which is sorted by
another column of the dataframe.
Now I would like to remove some elements of the integer, which are near to
others by their value. For example:
integer: c(1,20,2,21)
One of the reasons it might not be working is that you are changing the
index of the 'for' within the loop. The following is from the help page for
'for':
The index seq in a for loop is evaluated at the start of the loop; changing
it subsequently does not affect the loop. The variable var has
All,
thanks for your help.
Dieter,
thanks, it's a different way of tackling the problem.
But I still need a for loop to scroll throug the list?
For example:
c(1,2,3,5,)
and a threshold of 3, then c(1,5) should remain. If I make an integer with the
difference between each element and the
Hi,
I have an integer which is extracted from a dataframe, which is sorted by
another column of the dataframe.
Now I would like to remove some elements of the integer, which are near to
others by their value. For example: integer: c(1,20,2,21) should be c(1,20).
I tried to write a function,