I had a data frame with dates, I would like to add another column to df1 with time difference between between the date in $Date and the first entry in df2$Cov.Date, in weeks. so it should look like the following.
This is the data frame that I have, df1, that I would like to add an extra column to:
df1 <- data.frame (Id = c("1", "1", "2","2"),
Date = c("2005-02-05", "2005-04-05", "2005-01-15","2005-02-11")
)
This is df2, I would like to pull the first $Date entry from here
df2 <- data.frame (Id = c("1", "1", "1"),
Date = c("2004-12-06", "2005-01-02", "2005-01-15")
)
This is what I would like for df1 to look like:
df1 <- data.frame (Id = c("1", "1", "2","2"),
Date = c("2005-02-05", "2005-04-05", "2005-01-15","2005-02-11")
t = c(7.14, 14.29, 2.86, 6.71)
)
I can manually add a column with times, but I can't get it to automatically populate a new column with the difference in time from a date and an origin date