nucleo_uni<-function(x){
    apply(x,2,function(u) ifelse(abs(u)<1,1/2,0))
}
nucleo_est<-function(x,muestra,h,nucleo){
    apply(nucleo(outer(x,muestra,"-")/h),1,"mean")/h
}

library(MASS)
data(geyser)
attach(geyser)
hist<-hist(waiting)
plot(hist,freq=F)
hist(waiting,breaks=50,freq=F)
hist(waiting,breaks=100,freq=F)


x<-seq(min(waiting),max(waiting),by=0.01)
h<-4

est_dens<-nucleo_est(x,waiting,h,nucleo_uni)
windows()
plot(hist,freq=F)
lines(x,est_dens)
