[R] "inahull” from package alphahull not working when used with apply

Camilo Mora cmora at Dal.Ca
Mon Oct 27 06:05:37 CET 2014


Hi everyone,

I have a two column (x,y) database with say 20 million rows. I want to check the points that are inside of a hull created with the package alphahull. The function that does this is call “inahull”, and it runs well when I use it for one point at a time. But when I try to optimize the function using “apply”, it gives me the wrong results. I wonder what I am doing wrong? Below is the code: I also wonder if "inahull", could be used in data.table?

library (alphahull)
DT<-data.frame(x=c(0.25,0.75,0.75,0.25),y=c(0.25,0.25,0.75,0.75))

#creates hull
HULL<-ahull(DT, alpha=0.5)

#generate two points as test
TEST<-data.frame(x=c(0.25,0.5),y=c(0.5,0.5))
TEST<-data.matrix(TEST)

#check individual points
InPoint1<-inahull(HULL, c(TEST[1,1],TEST[1,2]))
InPoint2<-inahull(HULL, c(TEST[2,1],TEST[2,2]))

> InPoint1
[1] FALSE
> InPoint2
[1] TRUE

#repead check using apply
in2D=apply(TEST, 1,function(x, y) inahull(HULL, p = TEST))
> in2D
[1] FALSE FALSE





	[[alternative HTML version deleted]]



More information about the R-help mailing list