如何从特定的值出现开始计算数据中的行数

时间:2017-10-25 15:59:38

标签: r

structure(list(PROD_DATE = structure(c(1465876800, 1465963200, 
1466049600, 1466136000, 1466222400, 1466308800, 1466395200, 1466481600, 
1466568000, 1466654400), class = c("POSIXct", "POSIXt"), tzone = ""), 
    FILENUM = c(51922L, 51922L, 51922L, 51922L, 51922L, 51922L, 
    51922L, 51922L, 51922L, 51922L), CHOKE_SETTING = c(16L, 18L, 
    50L, 40L, 30L, 23L, 29L, 32L, 35L, 30L)), .Names = c("PROD_DATE", 
"FILENUM", "CHOKE_SETTING"), row.names = c(NA, -10L), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"), vars = "FILENUM", drop = TRUE, indices = list(
    0:9), group_sizes = 10L, biggest_group_size = 10L, labels = structure(list(
    FILENUM = 51922L), row.names = c(NA, -1L), class = "data.frame", vars = "FILENUM", drop = TRUE, .Names = "FILENUM"))


    df <- df %>% group_by(FILENUM) %>% arrange(PROD_DATE) %>%
                    mutate(DAYS_ON = row_number())

我正在使用上面的代码开始对数据集的行进行编号,以计算自开始以来的天数。而不是在prod_date中使用日期时间变量。

我不确定如何添加另一列,该列计算自其他列中出现最大值以来的天数。它应该开始计算第一行的值为50.前一行可以是NA或0

0 个答案:

没有答案