Suppose I have the following data.
A <- c(4,4,4,4)
B <- c(1,2,3,4)
C <- c(1,2,4,4)
D <- c(3,2,4,1)
data <- as.data.frame(rbind(A,B,C,D))
data <- t(data)
data <- as.data.frame(data)
> data
A B C D
V1 4 1 1 3
V2 4 2 2 2
V3 4 3 4 4
V4 4 4 4 1
I am looking to add 2 rows at the bottom. I tried rbind(data,colSums(data)) but it is giving me an error, and I'm having trouble finding something that will simply add a row.
The first row added needs to be the sum of the 1st 3 rows in each column. The second added row needs to be the sum of all 4 rows in each column.
so the output should look like this:
> data
A B C D
V1 4 1 1 3
V2 4 2 2 2
V3 4 3 4 4
V4 4 4 4 1
V1:V3Sum 12 6 7 9
V1:V4Sum 16 10 11 10
If you want to take a stab, I'm then trying to get relative frequencies so adding another 5 rows.
1 row would be for each value in a column (V1:V4) divided by the v1:v5Sum value (4 rows). Then a 5th row would be the v1:v3Sum divided by the v1:v5Sum.
> data
A B C D
V1 4 1 1 3
V2 4 2 2 2
V3 4 3 4 4
V4 4 4 4 1
V1:V3Sum 12 6 7 9
V1:V4Sum 16 10 11 10
relFreqV1 .25 .1 .09 .3 *each of these 4 rows is the value in
relFreqV2 .25 .2 .18 .2 row 1:4 divided by v1:v4Sum
relFreqV3 .25 .3 .36 .4
relFreqV4 .25 .4 .36 .1
relFreqTot .75 .6 .63 .9 * last row is v1:v3Sum divided by
V1:V4Sum
Any help is always appreciated!!!