I have a data frame (DF) with 3 columns with values and 200 columns with only a heading and NA values. As an an example:
Row Price Qty 2.10 2.15 2.20 2.25 ....
1 2.10 100 0 0 0 0
2 2.15 200 0 0 0 0
3 2.25 100 0 0 0 0
4 2.10 100 0 0 0 0
5 2.25 300 0 0 0 0
I am attempting to use dplyr and mutate_each to pass a function to all columns 4:n that uses the column headers name. The function will mutate each column so that for in the row where Price = Column Name, then the Qty amount is applied. See desired results bellow:
Row Price Qty 2.10 2.15 2.20 2.25 ....
1 2.10 100 100 0 0 0
2 2.15 200 0 200 0 0
3 2.25 100 0 0 0 100
4 2.10 100 100 0 0 0
5 2.25 300 0 0 0 300
Any thoughts on how to execute this?
# input data
DF <- structure(list(Row = 1:5, Price = c(2.1, 2.15, 2.25, 2.1, 2.25
), Qty = c(100L, 200L, 100L, 100L, 300L), X2.10 = c(0L, 0L, 0L,
0L, 0L), X2.15 = c(0L, 0L, 0L, 0L, 0L), X2.20 = c(0L, 0L, 0L,
0L, 0L), X2.25 = c(0L, 0L, 0L, 0L, 0L)), .Names = c("Row", "Price",
"Qty", "2.10", "2.15", "2.20", "2.25"), class = "data.frame", row.names = c(NA,
-5L))