Reputation: 925
My dataset is like the following example
Tier Decile
1 1
1 1
2 1
3 1
2 1
2 2
1 2
3 2
3 2
3 2
1 3
2 3
2 3
3 3
3 3
I want to get the answer like the following if the simple count or may be in the percentage. Is lapply or Aggregate function can work ?
Tier Decile1 Decile2 Decile3
Tier= 1 2 1 1
Tier = 2 2 1 2
Tier = 3 1 2 2
Upvotes: 1
Views: 98
Reputation: 61204
Use table
. Assume df
is your data.frame
> with(df, table(Tier, Decile))
Decile
Tier 1 2 3
1 2 1 1
2 2 1 2
3 1 3 2
Upvotes: 3