Public
Edited
Feb 2, 2023
Insert cell
Insert cell
Insert cell
Inputs.table(who)
Insert cell
Insert cell
Inputs.table(
tidy(
who,
pivotLonger({ cols: startsWith('new'), namesTo: 'key', valuesTo: 'cases' }),
filter(d => d.cases !== 'NA'),
mutate({ key: d => d.key.replace('newrel', 'new_rel') }),
// separate equivalent:
mutate({
key: d => d.key.split('_'),
new: d => d.key[0],
type: d => d.key[1],
sexage: d => d.key[2]
}),
// separate equivalent:
mutate({
sexage: d => [d.sexage[0], d.sexage.substring(1)],
sex: d => d.sexage[0],
age: d => +d.sexage[1]
}),
mutate({
cases2: d => Number(d.cases) + 1, // just trying some number computations
cases_ratio: d => d.cases/d.cases2
}),
select(['-key', '-new', '-iso2', '-iso3', '-sexage'])
).slice(0, 20)
)
Insert cell
Insert cell
df_summaries = tidy(
cars,
groupBy(
['cyl', 'gear'],
[
summarize({
n: n(), // can't do, e.g., n()/mean('mpg')
mpg: mean('mpg'),
hp: mean('hp'),
wt: mean('wt')
})
]
),
select(['cyl', 'gear', everything()]),
arrange([desc('n'), desc('mpg')])
)
Insert cell
Inputs.table(df_summaries)
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more