accumulate return interval() object as numeric object

I used lubridate and tidyverse package to combine continuos time seriese.

library(tidyverse)
library(lubridate)

aedat <- tribble(
  ~act, ~subj, ~aeterm, ~aestar, ~aeend,
  "A", "001", "hot",  "2002-03-01", "2002-03-02",
  "A", "001", "hot",  "2002-03-03", "2002-03-04",
  "A", "001", "hot",  "2002-03-06", "2002-03-07",
  "A", "001", "cold",  "2002-03-01", "2002-03-04",
  "B", "002", "hot",  "2002-03-02", "2002-03-05",
  "B", "002", "hot",  "2002-03-01", "2002-03-02",
  "B", "002", "cold",  "2002-03-01", "2002-03-04",
)

int_comb <- function(int1,int2){
  end_int1 <- int_end(int1)
  star_int2 <- int_start(int2)
  diff_int <- (end_int1 - star_int2)/ddays(1)
  if(abs(diff_int)<=1){
    int_res <- int_start(int1)%--%int_end(int2)
    
  }
  else{
    int_res <- int2
    
  }
  return(int_res)
}

aedat_res <- aedat %>% mutate(aestar=ymd(aestar),aeend=ymd(aeend),aeint=interval(aestar,aeend)) %>% 
  group_by(act,subj,aeterm) %>% 
  arrange(aestar,.by_group=TRUE) %>% 
  mutate(aeint2 = accumulate(aeint,int_comb))

But the column aeint2 is not a interval object. The value of aeint2 is just the value of @.Data of inteval object lossing .@start

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.