My input
df1 <- data.frame(Row=c("row1", "row2", "row3", "row4", "row5"), A=c(1,2,3,5.5,5), B=c(2,2,2,2,0.5), C= c(1.5,0,0,2.1,3))
It looks like this:
# Row1 1 2 1.5 # Row2 2 2 0 # Row3 3 2 0 # Row4 5.5 2 2.1 # Row5 5 0.5 3
I want to get the sum of all these pairs of rows with the following equation. Suppose for the pairs Row1 and Row2: I want to multiply each column entry and sum them into one final answer, for example
- Answer Row1-Row2
(1*2) + (2*2)+ (1.5 *0) = 6 - Answer Row1-Row3
(1*3) + (2*2) + (1.5*0) = 7
I want to do all the analysis for each pair of rows and get a frame of the result data as follows:
row1 row2 6 row1 row3 7 row1 row4 12.65 row1 row5 10.5 row2 row3 10 row2 row4 15 row2 row5 11 row3 row4 20.5 row3 row5 16 row4 row5 34.8
How can I do this with R? Thanks so much for the comments.
source share