What would be the easiest way (if possible with tidyverse) to multiply each columns x1:x10 with their respective vector. For example: the first row of the new table would be: age = "one", x1 = x1 * 1, x2 = x2 * 2, x3 = x3 * 9, x4 = x4 * 4...etc
x <- data.frame(age = c("one", "two", "three", "four", "five","one", "two", "three", "four", "five"),
replicate(10,sample(0:5,5,rep=TRUE)),
time = c("one", "two", "three", "four", "five","one", "two", "three", "four", "five"),
vector = c("1-2-9-4-5-1-5-6-1-2",
"3-2-3-4-5-2-6-6-1-2",
"1-2-4-4-2-4-5-4-2-1",
"9-2-3-1-5-5-5-3-1-2",
"1-1-3-4-5-1-5-6-3-2"))
age X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 time vector
1 one 4 0 3 5 0 5 0 3 5 4 one 1-2-9-4-5-1-5-6-1-2
2 two 1 5 3 5 1 2 5 0 4 4 two 3-2-3-4-5-2-6-6-1-2
3 three 0 4 5 0 3 0 0 5 2 2 three 1-2-4-4-2-4-5-4-2-1
4 four 0 0 5 5 4 3 2 5 5 1 four 9-2-3-1-5-5-5-3-1-2
5 five 2 1 2 1 4 5 5 2 1 1 five 1-1-3-4-5-1-5-6-3-2
6 one 4 0 3 5 0 5 0 3 5 4 one 1-2-3-4-5-1-5-6-1-2
7 two 1 5 3 5 1 2 5 0 4 4 two 3-2-3-4-5-2-6-6-1-2
8 three 0 4 5 0 3 0 0 5 2 2 three 1-2-4-4-2-4-5-4-2-1
9 four 0 0 5 5 4 3 2 5 5 1 four 9-2-3-1-5-5-5-3-1-2
10 five 2 1 2 1 4 5 5 2 1 1 five 1-1-3-4-5-1-5-6-3-9
I could do it by splitting the last column into multiple columns and then multiply each one but I'm looking for a faster way
thanks
