Displaying 3 results from an estimated 3 matches for "cumx".
Did you mean:
cmx
2007 Nov 20
1
Vectorization/Speed Problem
...out
introducing a for()! Here is my shot at a vectorized solution, as far as I
can take it.
Preliminary Vectorized Code:
X <- matrix(sample(c(1,0,0,0,0), 500, replace = TRUE), 25, 20, byrow=TRUE)
colnames(X) <- c(paste("a", 1:20, sep=""))
noX <- X; noX[X!=0] <- 0; cumX <- noX; cumNoX <- noX; Y1 <- noX; Y2 <- X; Y3
<- X
for (e in 1:ncol(X)) {
cumX[,e] <- cumsum(X[,e])
noX[X[,e] < 1 & cumsum(X[,e]) > 0 ,e] <- 1
cumNoX[,e] <- cumsum(noX[,e])
}
Y1[cumNoX > 0] <- cumNoX[cumNoX > 0] + 1
Y2[X == 0 & noX > 0] <- Y...
2006 Sep 11
2
faster way?
Hi,
Is there a faster way to do this? It takes forever, even on a
moderately sized dataset.
n <- dim(dsn)[1]
dsn2 <- dsn[order(-dsn$xhat),]
dsn2[1, "cumx"] <- dsn2[1, "xhat"]
for (i in 2:n) {
dsn2[i, "cumx"] <- dsn2[i - 1, "cumx"] + dsn2[i, "xhat"]
}
[[alternative HTML version deleted]]
2001 May 14
0
followup: lookup function for density(...) objects
...p: \"l\" for linear interpolation between data points")
cat("\n \"s\" for spline fit using data points\n\n")
}
n <- length(density.obj$x)
dx <- density.obj$x[2:n] - density.obj$x[1:(n-1)]
x <- rep(NA, length(p))
# midpoints
cumx <- (density.obj$x[2:n] + density.obj$x[1:(n-1)]) / 2
# numerical integration
cumy <- cumsum((density.obj$y[2:n] + density.obj$y[1:(n-1)]) / 2 * dx)
if(interp == "l")
{
Fx <- approxfun(cumy, cumx) # linear interpolation function
x <- Fx(p) #...