I want to convert a data frame (df
) into a different data frame (df1
), where the rows of df1
correspond to the frequency of occurrence of column B (df
). That is, in data frame df1
, the values in the rows correspond to the number of times they appear in column B of df
for a particular variable of column 'A' of df
. Here is an example:
df
A B
1. 21 2011
2. 21 2012
3. 21 2011
4. 22 2013
5. 22 2011
6. 23 2012
7. 23 2011
8. 23 2012
9. 23 2014
df1
2011 2012 2013 2014
1. 21 2 1 0 0
2. 22 1 0 1 0
3. 23 1 2 0 1