I have a csv dataset which is similar to the following:
Age Food_1_1 Food_1_2 Food_1_3 Amount_1_1 Amount_1_2 Amount_1_3
6 a b a 2 3 4
6 b b c 1 2 3
6 c a 4 1
9 c c b 1 3 1
9 c a b 1 2 1
Using R, I want to get the following data set which contains new set of columns a, b and c by adding the corresponding values:
Age Food_1_1 Food_1_2 Food_1_3 Amount_1_1 Amount_1_2 Amount_1_3 a b c
6 a b a 2 3 4 6 3 0
6 b b c 1 2 3 0 3 3
6 c a 4 1 1 0 4
9 c c b 1 3 1 0 1 4
9 c a b 1 2 1 2 1 1
Note: My data also contains missing values. The variables Food_1_1:Food_1_3 are factors and the variables Value1:Value3 are numeric. For more clearity: 1st row of column "a" contains the addition of all amount through Amount_1_1 to Amount_1_3 related to a (say for example 2+4 =6).