i have five columns. person_id, in_date, out_date, week_rounded (rounded to the first sunday of each week), and house. it is a long dataset, and I provided a subset below. the in_date and out_date are the same for each visit spell at someone's house. I am quite stuck..
how do i make a new variable that calculates total days spent for a given week at someone's house? (note the weeks begin on Sunday)
Reproducible data example:
structure(list(person_id = c("A", "A", "A", "A", "A", "A", "A",
"A", "A"), in_date = structure(c(1635984000, 1635984000, 1635984000,
1635984000, 1658534400, 1658534400, 1658966400, 1658966400, 1658966400
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), out_date = structure(c(1658534400,
1658534400, 1658534400, 1658534400, 1658966400, 1658966400, 1660089600,
1660089600, 1660089600), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
week_rounded = structure(c(1656201600, 1656806400, 1657411200,
1658016000, 1658016000, 1658620800, 1658620800, 1659225600,
1659830400), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
house = c("Janelle", "Janelle", "Janelle", "Janelle", "Lisa",
"Lisa", "Bob", "Bob", "Bob"), days_spent_in_week = c(NA,
NA, NA, NA, NA, NA, NA, NA, NA)), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -9L))
please help me fill the days_spent_in_week variable using tidyverse. I am very stuck!