Skip to content

Instantly share code, notes, and snippets.

@rrblogdatascience
Created July 2, 2015 21:08
Density estimate and histogram computation
# SCRIPT_STR('
x <- .arg1
xanz <- .arg2
density_estimate <- density(rep(x, xanz))
dens <- sapply(x, function(i){
which.min(abs(i - density_estimate$x))
})
hist_density <- hist(rep(x, xanz), freq=FALSE,
breaks=c(x,max(x)+median(diff(x))), right = F)
return(paste(density_estimate$y[dens],hist_density$density,sep="~"))
# ',
# MAX([x bin]), COUNT([x axis (raw)]) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment