I am relatively new to R and have a data frame that looks like this:
df <- structure(list(row.names = 1:5, date = c("01-01-2017", "10-01-2017",
"10-04-2017", "11-04-2017", "12-04-2017"), fixed_factor = c(NA,
3L, 2L, 5L, 10L), line_1_rec_1_mean = c(0.5, 0.1, 0.05, 0.05,
0.1), line_1_rec_2_mean = c(6, 5, 3, 2, 0.9), line_1_rec_3_mean = c(88L,
3L, 4L, 3L, 7L), line_1_rec_5_mean = c(6, 0.2, 0.7, 0.6, 3),
line_1_rec_6_mean = c(50L, 1L, 5L, 8L, 2L)), row.names = c(NA,
-5L), class = "data.frame")
row.names date fixed_factor line_1_rec_1_mean line_1_rec_2_mean line_1_rec_3_mean line_1_rec_5_mean line_1_rec_6_mean
1 1 01-01-2017 NA 0.5 6 88 6 50
2 2 10-01-2017 3 0.1 5 3 0.2 1
3 3 10-04-2017 2 0.05 3 4 0.7 5
4 4 11-04-2017 5 0.05 2 3 0.6 8
5 5 12-04-2017 10 0.1 0.9 7 3 2
The real dataframe contains over 1,500 columns and 365 rows.
What I am trying to do is to add the "fixed_factor" for each row to all "line_1_rec*" columns. Which is all columns except the first three and save the resulting data set as a new data frame which would look sth like this:
row.names date fixed_factor line_1_rec_1_mean line_1_rec_2_mean line_1_rec_3_mean line_1_rec_5_mean line_1_rec_6_mean
1 1 01-01-2017 NA 0.50 6.0 88 6.0 50
2 2 10-01-2017 3 3.10 8.0 6 3.2 4
3 3 10-04-2017 2 2.05 5.0 6 2.7 7
4 4 11-04-2017 5 5.05 7.0 8 5.6 13
5 5 12-04-2017 10 10.10 10.9 17 13.0 12
I have done alot of reading but have not managed to find a solution. Any help would be greatly appreciated.