使用dplyr根据R中的前一行创建计算列

时间:2019-06-12 03:33:42

标签: r function dataframe dplyr apply

router.get("/:username", function(req, res, next) {
  if (req.params.username === "login") {
    res.render("login", { data: null });
  } else if (req.params.username === "view") {
    res.render("viewError", { data: null });
  } else {
    res.render("profile", { data: req.params.username });
  }
});

router.get("/view/:id", function(req, res, next) {
  res.render("view", { data: req.params.id });
});

我正在尝试为第一行和第二行计算一个称为成长structure(list(state = c("Himachal_Pradesh", "Himachal_Pradesh", "Himachal_Pradesh", "Himachal_Pradesh", "Himachal_Pradesh", "Himachal_Pradesh"), town_names = c("town_a", "town_a", "town_a", "town_a", "town_a", "town_a"), sales_growth = c(67784.15767, 67784.15767, 67784.15767, 67784.15767, 67784.15767, 67784.15767 ), key = c("growth_in_2019", "growth_in_2019", "growth_in_2019", "growth_in_2019", "growth_in_2019", "growth_in_2019"), value = c(0.0220237807164989, 0.0220237807164989, 0.0220237807164989, 0.0220237807164989, 0.0220237807164989, 0.0220237807164989), year = c("2019", "2019", "2019", "2019", "2019", "2019"), dates = structure(c(17896, 17927, 17955, 17986, 18016, 18047), class = "Date")), row.names = c(NA, -6L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), vars = c("state", "town1", "key"), drop = TRUE, indices = list(0:5), group_sizes = 6L, biggest_group_size = 6L, labels = structure(list( state = "Himachal_Pradesh", town_names = "town_a", key = "growth_in_2019"), row.names = c(NA, -1L), class = "data.frame", vars = c("state", "town1", "key" ), drop = TRUE)) 的新列:它必须获取上一行的值,然后计算:Formula = traffic*(1+value)。它必须要增加订单。

previous_row*(1+value)

0 个答案:

没有答案