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, but
Bart Joosen 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) should
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 the
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 previo
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
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
er of 2, while I'm going to work with an integer of only about 800).
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:
Se