I have this data set:
created On | status
---------------------
2021-10-21 | complete
2021-10-21 | complete
2021-10-21 | partial complete
2021-10-21 | on going
2021-10-20 | partial complete
2021-10-20 | on going
2021-10-19 | complete
I am trying to create a pivot table like in excel which expected output like below:
created on | complete | partial complete | on going | total | percent (complete+partial)/total
-----------------------------------------------------------------------------------------------------------
2021-10-21 | 2 | 1 | 1 | 4 | 50
2021-10-20 | 0 | 1 | 1 | 2 | 50
2021-10-19 | 1 | 0 | 0 | 1 | 100
When I tried the following:
daily_numbers1 %>%
pivot_table(
.rows = ~ `created on`,
.columns = ~ status,
.values = ~ status
)
I got a tibble with the following output:
created on | complete | partial complete | on going | total | percent (complete+partial)/total
-----------------------------------------------------------------------------------------------------------
2021-10-21 | <chr [2]> | <chr[1]> | <chr [1]> | 4 | 50
2021-10-20 | <NULL> | <chr [1]> | <chr [1]> | 2 | 50
looks like i showed characters instead of number counts. I am still figuring our how to add the total and percent column. If you could add that too.
Another method I tried:
daily_numbers1 %>%
group_by(`Created On`) %>%
summarize(status = count(status))
i got this instead:
status | freq
---------------------
complete | 3
partial | 2
on going | 2
far from what I needed, grouped by date.