I have the following dataframe imported in R:
product per1 per2 per3
A 10 20 30
B 23 14 21
C 26 95 81
Consider A:C as products listed in rows one after another and their corresponding sales values across per_1:per_3 which are given in columns.
The number of products are quite high so couldn't list all the products My requirement here is to add the sales for a combination of products.
For example
A 10 20 30
B 23 14 21
The sum should be
myresult<- A+B
myresult
33 34 51
The sum should be 30 34 80, and it should be copied to another vector.
The number of products are so large that I could not transpose them and use it for the calculation. Assume the combination of products to be added are also high and random.
Here's my data:
structure(list(product = structure(1:3, .Label = c("A", "B", "C"), class = "factor"),
per1 = c(10, 20, 30),
per2 = c(23, 14, 21),
per3 = c(26, 95, 81)),
.Names = c("product", "per1", "per2", "per3"),
row.names = c(NA, -3L), class = "data.frame")