2021年4月1日星期四

Sum columns based specific row and sum rows based on specific column as new variable

I want to construct a 2x2 contingency table to compute the odds ratio. However, I fail to sum up the rows and columns as I wanted them to be. This is my contingency table for now. I want to total up Down Steady and Up into a new variable named Yes.

|        |Down|No|Steady|Up|  |--------|----|--|------|--|  |Female  |    |  |      |  |  |Male    |    |  |      |  |  |Female.1|    |  |      |  |  |Male.1  |    |  |      |  |  |Female.2|    |  |      |  |  |Male.2  |    |  |      |  |  

I have tried using colsums but it just totals up the entire column. The output I want is like this:

|      |Yes|No|  |------|---|--|  |Female|   |  |  |Male  |   |  |  

Thank you in advance!

https://stackoverflow.com/questions/66913303/sum-columns-based-specific-row-and-sum-rows-based-on-specific-column-as-new-vari April 02, 2021 at 09:06AM

没有评论:

发表评论