I am working with a covid dataset, and I got to get a counter from the first day that the virus appeared in said country
This is an example of my data
And this is my desired result
I have been trying with this code:
data1<-data1%>%
arrange(country,Date) %>%
group_by(Country) %>%
mutate(Counter= Date-first(Date)+1)
But just gets me a counter from day 1, how can I get that day 1 is from the day that confirmed is 1 for the first time.
Here is the example data:
structure(list(Date = structure(c(1577836800, 1577923200, 1578009600,
1578096000, 1578182400, 1578268800, 1578355200, 1578441600, 1577836800,
1577923200, 1578009600, 1578096000, 1578182400, 1578268800, 1578355200,
1578441600, 1577836800, 1577923200, 1578009600, 1578096000, 1578182400,
1578268800, 1578355200, 1578441600), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), country = c("Afganistan", "Afganistan", "Afganistan",
"Afganistan", "Afganistan", "Afganistan", "Afganistan", "Afganistan",
"Colombia", "Colombia", "Colombia", "Colombia", "Colombia", "Colombia",
"Colombia", "Colombia", "France", "France", "France", "France",
"France", "France", "France", "France"), confirmed = c(0, 0,
0, 0, 0, 1, 1, 2, 0, 0, 1, 1, 2, 3, 3, 3, 0, 0, 0, 0, 0, 1, 1,
1)), row.names = c(NA, -24L), class = c("tbl_df", "tbl", "data.frame"
))