r - Cut vector into groups -
a <- -30:30 cutsize <- 10 b <- %/% cutsize table(b) # output -3 -2 -1 0 1 2 3 10 10 10 10 10 10 1
wanted output
-3 -2 -1 0 1 2 3 10 10 10 1 10 10 10
i need divide vector groups (by cutsize
). used %/%
, apparently "shifts" groups. want group:
- zero group
0
- everything 1 10 group
1
- from 11 20 group
2
- ...
here's bit awkword solution
table(ceiling((a / cutsize) * sign(a)) * sign(a)) # -3 -2 -1 0 1 2 3 # 10 10 10 1 10 10 10
or similarly
table(ceiling(abs(a / cutsize)) * sign(a)) # -3 -2 -1 0 1 2 3 # 10 10 10 1 10 10 10
Comments
Post a Comment