Reputation: 245
My dataset looks like this
98 11
99.5 12
100 12
101 13
100.2 10
100.5 10.5
I want to create a result set which looks like this
10-11 11-12 12-13
98-99 1 1 0
99-100 0 1 0
100-101 2 1 1
Any help is welcome.
Upvotes: 1
Views: 140
Reputation: 54370
The boundary condition is not well specified in your question, you should get:
> table(cut(DS[,1], c(98:101), right=FALSE), cut(DS[,2], c(10:13), right=TRUE))
(10,11] (11,12] (12,13]
[98,99) 1 0 0
[99,100) 0 1 0
[100,101) 1 1 0
Or this:
> table(cut(DS[,1], c(98:101), right=FALSE), cut(DS[,2], c(10:13), right=FALSE))
[10,11) [11,12) [12,13)
[98,99) 0 1 0
[99,100) 0 0 1
[100,101) 2 0 1
But not the one you show in OP.
Upvotes: 3