If my writing seems troublesome, please see the attached pic. enter image description here I would like to have generalized code, so that I can apply that to a very large file. Any numeric calculation for formula for 2/3 rows/columns won't be helpful for me. Suppose I have a following CSV table:
Class1 Count1
1 1
2 1
1 0
3 1
1 1
1 1
3 0
3 1
2 1
Now I would like to have summation based on the values of class in a new column. Suppose we get two new columns named Class2 and Count2, as per my desire the top most cell (in the first row) of Count2 should have the sum of all the values in column "Count1" corresponding to "1" in column "Class1", the next-to top most cell (in the 2nd row) of Count2 should have the sum of all the values in column "Count1" corresponding to "2" in Class1, and so on. After running the code, I would like to have a table like following:
Class1 Count1 Class1 Count2
1 1 1 3
2 1 2 2
1 0 3 2
3 1
1 1
1 1
3 0
3 1
2 1
I work on social sciences, so this type of work is very tough for me. It will be of great help if anyone give me R code for executing this. Thanks in Advance.