R/lengthintervals.R

`lengthintervals` <-
function (X, I, type = "midpoints", neighbours, closest) 
{

o <- as.column(order(X))
lengths <- matrix(0, 1, length(X))
d <- neighbours

if (closest) {
	initialnbrs <- matrix(0, length(X), neighbours)
        if (type == "average") {
        	for (i in 1:length(X)) {
                	out <- getnbrs(X, o[i], order(X), neighbours, closest)
                	initialnbrs[i, ] <- out$nbrs
                	lengths[i] <- sum(abs(rep(X[o[i]], times = d) - X[initialnbrs[i, ]]))/d
            	}
        }
	if (type == "midpoints") {
		lengths<-I[2:length(I)]-I[1:length(X)] 
        }
}
else {
	lengths<-I[2:length(I)]-I[1:length(X)]
}
    
return(as.row(lengths))
}

Try the adlift package in your browser

Any scripts or data that you put into this service are public.

adlift documentation built on March 31, 2023, 11:03 p.m.