2016-08-01 9 views

答えて

0
get_count <- function(x, y, h) { 
    my_dist <- function(x2, y2) { 
    return(sqrt((x - x2)^2 + (y - y2)^2)) 
    } 

    distances <- mapply(my_dist, attr(h, 'xcm'), attr(h, 'ycm')) 

    return(attr(h, 'count')[which.min(distances)]) 
} 
5

library(hexbin)のhexbin関数を使用していると仮定すると、ビンIDを使用して必要なものを得ることができます。

関数をhexbin(..., IDs = T)と呼びます。結果には、どのビンがポイントになるかを示すフィールドがあります。

の作業例:

library(hexbin) 

x <- c(1, 1.2, 1, 3, 5, -2 ,1, 0, 0.8) 
y <- c(1, 1, 0, -1, 0, 2, -1, 1, 1) 

h <- hexbin(x, y, xbins = 3,IDs = T) 

#what is the cell ID of point 1? 
ID1 <- [email protected][1] 

#how many points fall in that cell? 
sum([email protected] == ID1) #answer is 4 in this case 
関連する問題

 関連する問題