Why not just > library (alphahull) > DT=data.frame(x=c(0.25,0.25,0.75,0.75),y=c(0.25,0.75,0.75,0.25)) > Hull <- ahull(DT, alpha = 0.5) > TEST<- data.frame(x=c(0.25,0.5),y=c(0.5,0.5)) > apply(TEST, 1, function(x) inahull(Hull, x)) [1] FALSE TRUE
------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bart Kastermans Sent: Monday, October 27, 2014 2:10 PM To: r-help@r-project.org Subject: Re: [R] "inahull? from package alphahull not working when used with lapply On 27/10/14 19:42, Camilo Mora wrote: > Hi Bart, > > Even after putting the variables in the apply function, the results come not > right: > > library (alphahull) > DT=data.frame(x=c(0.25,0.25,0.75,0.75),y=c(0.25,0.75,0.75,0.25)) > Hull <- ahull(DT, alpha = 0.5) > > TEST<- data.frame(x=c(0.25,0.5),y=c(0.5,0.5)) > plot(Hull) > points(TEST) > > InHul2D <- function(Val1, Val2, Hull) inahull(Hull, p = c(Val1, Val2)) > > IN <- apply(TEST, 1, function(x,y) InHul2D("x","y",Hull)) > > Try with this version of your function: InHul2D <- function(Val1, Val2, Hull) { stopifnot(is.numeric(Val1), is.numeric(Val2)) inahull(Hull, p = c(Val1, Val2)) } And answer the question; why would you put quotes around x and y in InHul2D call in apply? Once you remove the quotes, and get the error "Error: argument "y" is missing, with no default" that I mentioned in my last email, look at my last email to find out why. I'll be happy to help you further with this, but then you have to explain the output you get from using my version of InHul2D (before you remove the quotes), and why my last email didn't solve the problem after you removed the quotes. Check ?stopifnot, and ?is.numeric Best, Bart ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.