Displaying 3 results from an estimated 3 matches for "whichclosest".
2006 Feb 13
5
search algorithm
Hi!
I have a problem of finding a specific value in a column. For example, I
have a matrix with say 2 columns
X Y
1 -2.0341602 9.036689e-05
2 -1.4287230 1.807338e-04
3 -1.1194402 2.711007e-04
4 -1.0327582 3.614676e-04
5 -0.8130556 4.518344e-04
6 -0.7138212 5.422013e-04
7 -0.6634425 6.325682e-04
8 -0.6512083 7.229351e-04
9
2002 Mar 28
0
Summary: Vectorizing closest match
...can use round(approx(x,1:length(x),xout=w,rule=2,ties='ordered')$y)
For S-Plus just remove ties=.
David James suggested using cut. I adapted his code and speeded it up as he suggested, by going right to the .C call in cut.default (set global variable .R. to TRUE for R, FALSE for S-Plus):
whichClosest <- function(x, w) {
## x: vector of reference values
## w: vector of values to find closest matches in x
## Returns: subscripts in x corresponding to w
i <- order(x)
x <- x[i]
n <- length(x)
br <- c(-1e30, x[-n]+diff(x)/2,1e30)
m <- length(w)
if(.R.) i[.C("b...
2003 Apr 22
0
Hmisc's aregImpute segfaults R-1.7.0 under linux
...(1000)
y <- x2 + 1*(x1=='c') + .2*x3 + rnorm(1000,0,2)
orig.x1 <- x1[1:250]
orig.x2 <- x2[251:350]
x1[1:250] <- NA
x2[251:350] <- NA
# Use 100 imputations to better check against individual true values
f <- aregImpute(~y + x1 + x2 + x3, n.impute=100)
Iteration:1 Error in whichClosest(pti[j], pti[nai]) : Incorrect number
of arguments (7), expecting 8 for bincode
I upgraded to the most recent version of Hmisc (verson 1.5-3) on both
platforms. This fixed the problem on OS X and aregImpute runs fine
there. But with Hmisc 1.5-3, aregImpute now causes R to segfault on my
linux b...