Hi everyone, This may be a trivial solution but I have not been able to figure what is wrong with this code.
The basic premise of the code is to use data.table to append a new column to a data.table that indicates if the values per row at two other columns are within a 2d hull generated with the package alphahull. I get the right results when I apply the function to a data.table with only the two columns to consider, But the results are off when I try to apply the same function selecting the two columns from a data.table with numerous columns. I think my problem is how the columns are selected for use in the function. Any help will be much appreciated. library (alphahull) library(data.table) #creates a hull 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) #applying the "inahull" function to a datatable with just the two colunms TwoColumn<- data.table(x=c(0.25,0.5,0.5,0.5,0),y=c(0.5,0.5,0.5,.5,0)) TwoColumn[, INHULL := apply(TwoColumn, 1, function(x) inahull(Hull, x))] #the results are correct #now if I apply the same function to a selection of two columns in a data.table with several columns, the codes dies not work ThreColumn<- data.table(w=c(1,2,3,4,5), z=c(1,2,3,4,5),x=c(0.25,0.5,0.5,0.5,0),y=c(0.5,0.5,0.5,.5,0)) ThreColumn[, INHULL := lapply(.SD, function(x) inahull(Hull, x)), .SDcols=c(x,y)] [[alternative HTML version deleted]] ______________________________________________ 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.