How to change the range of dates in an existing column R studio

I have a dataset that looks like this:

     d.date agesincetaggingdays rf8fitted n        freq taggingdate
1 2018-09-19                  69    Active 3 0.027777778  2018-07-12
3 2018-09-21                  71    Active 2 0.018518519  2018-07-12
4 2018-09-22                  72    Active 1 0.009259259  2018-07-12
5 2018-09-23                  73    Active 6 0.055555556  2018-07-12
6 2018-09-24                  74    Active 8 0.074074074  2018-07-12

etc…

This dataset is a subset of another one that I subsetted to get the rf8fitted “Active”.
Basically this subset represents the frequencies of the “Active” behavior of a bird specie for a given day.

It is not shown here but some days the birds aren’t active at all. Thus, some dates are missing from this subset, especially when the dates are outside the minimum and maximum dates.

My question is: I want to change the range of my d.date column so it matches the d.date column from my original dataframe. Basically I want all the dates of my original dataframe even if birds are not active. Instead, I want the other columns to be either NA’s, or 0’s.

I’ve tried like this:

a <- ymd(min(alm18subset$d.date))
b <- ymd(max(alm18subset$d.date))
alm18freq$d.date <- seq(a, b, by = "days")

where alm18subset is my original dataframe. But it returns me an error that says that the number of lines don’t match.

Is there a way to do that ? Thanks !

Read more here: Source link