Behaviour of Inf in hist breaks, R -


i use rs hist function bin counts. since in don't know lowest or highest value used -inf , inf first , last break. instead of counting -inf first break, , last break inf r puts values in first bin.

> hist(1:100, breaks=c(0, 50, 100), plot=f)$counts [1] 50 50 > hist(1:100, breaks=c(-inf, 50, 100), plot=f)$counts [1] 100   0 > hist(1:100, breaks=c(0, 50, inf), plot=f)$counts [1] 100   0 > hist(1:100, breaks=c(-inf, 50, inf), plot=f)$counts [1] 100   0 

i expect 4 lines give same output don't. expected behaviour? , there simple workarounds problem?

edit: ended using table , cut instead:

table(cut(1:100, breaks=c(-inf, 50, inf))) 

it causes issues hist because width of blocks becomes infinite , default hist considers areas of blocks in computations:

the default non-equi-spaced breaks give plot of area one, in area of rectangles fraction of data points falling in cells.

you best off using single value version of breaks argument: number of breaks use. default choose sensible breaks data:

str(hist(1:100, breaks=3, plot=f)) list of 6  $ breaks  : num [1:3] 0 50 100  $ counts  : int [1:2] 50 50  $ density : num [1:2] 0.01 0.01  $ mids    : num [1:2] 25 75  $ xname   : chr "1:100"  $ equidist: logi true  - attr(*, "class")= chr "histogram" 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -