次のようなデータセットがあります。
partyid coninc
Ind,Near Dem 25926
Not Str Democrat 33333
Not Str Democrat 41667
Strong Democrat 69444
Ind,Near Dem 60185
Ind,Near Dem 50926
Ind,Near Dem 18519
Strong Democrat 3704
Strong Democrat 25926
Strong Democrat 18519
Not Str Republican 18519
Strong Democrat 18519
Not Str Democrat 18519
私がやりたいのは、データセットを次のような形式にフォーマットすることです。
partyid 0-50,000 50,000-100,000 100,000-150,000 >150,000
Strong Democrat 2344 3423 4342 54
Not Str Democrat 2643 934 ..
Ind, Near Dem 7656 343 ..
Ind, Near Rep 7655 833 ..
Not Str Republican 2443 343
Strong Republican 3444 773
つまり、行を partyid 変数のレベルで並べ替え、列を coninc 変数の範囲のカウントで並べ替えます。
dput
私のデータのA :
structure(list(partyid = structure(c(3L, 2L, 2L, 1L, 3L, 3L, 3L, 1L, 1L, 1L, 5L, 1L, 2L, 1L, 1L, 4L, 4L, 3L, 4L, 3L), .Label = c("Strong Democrat", "Not Str Democrat", "Ind,Near Dem", "Ind,Near Rep", "Not Str Republican", "Strong Republican"), class = "factor"), coninc = c(25926L, 33333L, 41667L, 69444L, 60185L, 50926L, 18519L, 3704L, 25926L, 18519L, 18519L, 18519L, 18519L, 25926L, 18519L, 33333L, 25926L, 60185L, 69444L, 50926L)), .Names = c("partyid", "coninc"), row.names = c(1L, 2L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L), class = "data.frame")