0
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())

I'm using the code above to start numbering the rows of the dataset to count days since the start. Rather than using Date-time variable in prod_date.

I am unsure how to add another column that counts days since the occurrence of a max value in a different column. It should start counting the first row at the value of 50. Previous rows would either be NA or 0

Brent B
  • 5
  • 3
  • 2
    Welcome to SO! Could you please post a minimum, reproducible example (see https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? Also as a start it would be very helpful to see part of your data. You can do this with `dput(head(df,10))` – Mike H. Oct 25 '17 at 16:02
  • Please, [edit] your question and show the expected result. It is not clear from you description because `CHOKE_SETTING` is continuously increasing. Please note that simply counting rows instead of days might go fail if is there are gaps in the date sequence or multiple rows per day. – Uwe Oct 25 '17 at 16:15
  • There is only 1 row per day. I have updated the values to show a max that then decreases. – Brent B Oct 25 '17 at 17:28

0 Answers0