tidy_data2 = tidy(
covid_data,
pivotLonger({
cols: time_keys,
namesTo: 'date',
valuesTo: 'cases',
}),
rename({'Country/Region': 'country'}),
map(d => ({...d, date: formatTime(Date.parse(d.date))})),
groupBy(['country', 'date'], [
summarize({
cases: sum('cases'),
})
]),
mutateWithSummary({
prev_cases: lag('cases', { default: 0 }),
}),
mutate({
new_daily: (d) => d.cases - d.prev_cases < 0 ? 0 : d.cases - d.prev_cases,
})
)