
У меня есть набор данных с переменной ColumnStart, которая идентифицирует первый столбец для вычисления среднего значения.У меня есть вторая переменная ColumnEnd, которая идентифицирует последний столбец в этом вычислении.Для первой строки я хотел бы вычислить среднее значение от столбца 5 до столбца 9. второй ряд от столбца 6 до 11 и т. Д.
Вывод будет:

Вот обновленный dput из R:
structure(list(ID = c("AAA", "BBB", "CCC", "DDD"), ShortID = c("452L",
"3L", "4L", "324L"), Name = c("PS1", "PS2", "PS3", "PS4"), Route =
c("Internal",
"External", "Internal", "Internal"), ColumnStart = c(7L, 7L,
9L, 8L), ColumnEnd = c(9L, 11L, 13L, 10L), Date1 = c(1L, 5L,
13L, 4L), Date2 = c(2L, 6L, 45L, 3L), Date3 = c(3L, 7L, 23L,
2L), Date4 = c(4L, 8L, 65L, 1L), Date5 = c(5L, 8L, 34L, 3L),
Date6 = c(6L, 9L, 23L, 5L), Date7 = c(7L, 6L, 54L, 6L), Date8 = c(7L,
6L, 1L, 7L), Date9 = c(8L, 9L, 3L, 8L)), .Names = c("ID",
"ShortID", "Name", "Route", "ColumnStart", "ColumnEnd", "Date1",
"Date2", "Date3", "Date4", "Date5", "Date6", "Date7", "Date8",
"Date9"), row.names = c(NA, -4L), class = c("tbl_df", "tbl",
"data.frame"), spec = structure(list(cols = structure(list(ID =
structure(list(), class = c("collector_character",
"collector")), ShortID = structure(list(), class =
c("collector_character",
"collector")), Name = structure(list(), class = c("collector_character",
"collector")), Route = structure(list(), class = c("collector_character",
"collector")), ColumnStart = structure(list(), class =
c("collector_integer",
"collector")), ColumnEnd = structure(list(), class =
c("collector_integer",
"collector")), Date1 = structure(list(), class = c("collector_integer",
"collector")), Date2 = structure(list(), class = c("collector_integer",
"collector")), Date3 = structure(list(), class = c("collector_integer",
"collector")), Date4 = structure(list(), class = c("collector_integer",
"collector")), Date5 = structure(list(), class = c("collector_integer",
"collector")), Date6 = structure(list(), class = c("collector_integer",
"collector")), Date7 = structure(list(), class = c("collector_integer",
"collector")), Date8 = structure(list(), class = c("collector_integer",
"collector")), Date9 = structure(list(), class = c("collector_integer",
"collector"))), .Names = c("ID", "ShortID", "Name", "Route",
"ColumnStart", "ColumnEnd", "Date1", "Date2", "Date3", "Date4",
"Date5", "Date6", "Date7", "Date8", "Date9")), default = structure(list(),
class = c("collector_guess",
"collector"))), .Names = c("cols", "default"), class = "col_spec"))