0

So I am working on weight declustering and I have been stuck on this tiny part for a while. I am supposed to use a weight correction factor for each value in a column. Basically the weight correction factor is : UpperBound/(Number of Values in the bin * Number of non Zero Bins) I got most of it figured out, but I am unable to extract the number of Values in each bin for a histogram and assign it to my value. I know that the hist$counts command will give me the count, however it is a smaller vector and I am unable to use it.

#Weight Declustering for all wells using looping
for( i in 1:length(lev)){
    wellf<- as.numeric(unlist(well[i]))
    mean(wellf)
    range(wellf)
    #Plot the histogram and get the bins including its bounds for each value of the well
    h<-hist(wellf)
    interval<-findInterval(wellf,h$breaks)
    h2<- .Last.value
    L<- sum(h$density!=0)
    #int<-cbind( value=wellf, lower=h$breaks[h2],   upper=h$breaks[h2+1],count=h$counts,L)
    int<-cbind( value=wellf, upper=h$breaks[h2+1],L)
    #Use dplyr cause its easier and effective
    int<- tbl_df(data.frame(int))
    int<- int %>% mutate(count= length(which(int$upper==int$upper)))
    declus<- int %>% mutate(weighted= 1/(counts*L)) %>% mutate(new= weighted*value) %>% filter(new!=Inf)
    decluspor<- sum(declus$new)

}

So I am stuck at the point where I am required to compute counts. So the count should be of the same length as the others, and it should give the number of data contained in the bin containing the value.

+ value lower upper counts L count
+ 19.7    18    20      2 4     0
+ 18.5    18    20      0 4     0
+ 23.5    22    24      6 4     0

So in the table above the column 'counts' is supposed to contain the number of data contained in the bin which value belongs to. Like for 19.7 -- counts must be 2 because 19.7 is in the bin 18-20 and there is one other value along with 19.7.

Any help will be appreciated.

Cheers!

pjs
  • 18,696
  • 4
  • 27
  • 56

0 Answers0