Hello,
it should be an easy task but I am experiencing an issue.
As per title, I want to divide each cell of the crosstabulation by its column mean. I provide some reproducible example.
This is a small dataset:
Now the code to divide the cell values by the column mean:
These are the column means
new table:
In the above, some values are ok, some others are wrong.
For instance, the value in the cell in the 2nd row 1st column (0.4444) should be the same as in the cell above it (coz they both stem from 4 / 12.2), yet the value is different.
I got any clue as to why this is happening.
Gm
it should be an easy task but I am experiencing an issue.
As per title, I want to divide each cell of the crosstabulation by its column mean. I provide some reproducible example.
This is a small dataset:
C-like:
mydata <- structure(list(none = c(4, 4, 25, 18, 10), light = c(2, 3, 10,
24, 6), medium = c(3, 7, 12, 33, 7), heavy = c(2, 4, 4, 13, 2
)), row.names = c("SM", "JM", "SE", "JE", "SC"), class = "data.frame")
Code:
none light medium heavy
SM 4 2 3 2
JM 4 3 7 4
SE 25 10 12 4
JE 18 24 33 13
SC 10 6 7 2
C-like:
newtable <- data / apply(data, 2, mean)
Code:
none light medium heavy
12.2 9.0 12.4 5.0
Code:
none light medium heavy
SM 0.3278689 0.2222222 0.2419355 0.4000000
JM 0.4444444 0.2419355 1.4000000 0.3278689
SE 2.0161290 2.0000000 0.9836066 0.4444444
JE 3.6000000 1.9672131 3.6666667 1.0483871
SC 0.8196721 0.6666667 0.5645161 0.4000000
For instance, the value in the cell in the 2nd row 1st column (0.4444) should be the same as in the cell above it (coz they both stem from 4 / 12.2), yet the value is different.
I got any clue as to why this is happening.
Gm