- x
A data frame, data frame extension (e.g. a tibble), or a
lazy data frame (e.g. from dbplyr or dtplyr).
- ...
<data-masking
> Variables to group
by.
Named arguments passed on to dplyr::add_count
wt
<data-masking
> Frequency weights.
Can be NULL
or a variable:
If NULL
(the default), counts the number of rows in each group.
If a variable, computes sum(wt)
for each group.
sort
If TRUE
, will show the largest groups at the top.
name
The name of the new column in the output.
If omitted, it will default to n
. If there's already a column called n
,
it will use nn
. If there's a column called n
and nn
, it'll use
nnn
, and so on, adding n
s until it gets a new name.
.drop
Handling of factor levels that don't appear in the data, passed
on to group_by()
.
For count()
: if FALSE
will include counts for empty groups (i.e. for
levels of factors that don't exist in the data).
For add_count()
: deprecated since it
can't actually affect the output.
data
A data frame.
cols
<tidy-select
> List-columns to unnest.
When selecting multiple columns, values from the same row will be recycled
to their common size.
keep_empty
By default, you get one row of output for each element
of the list that you are unchopping/unnesting. This means that if there's a
size-0 element (like NULL
or an empty data frame or vector), then that
entire row will be dropped from the output. If you want to preserve all
rows, use keep_empty = TRUE
to replace size-0 elements with a single row
of missing values.
ptype
Optionally, a named list of column name-prototype pairs to
coerce cols
to, overriding the default that will be guessed from
combining the individual values. Alternatively, a single empty ptype
can be supplied, which will be applied to all cols
.
names_sep
If NULL
, the default, the outer names will come from the
inner names. If a string, the outer names will be formed by pasting
together the outer and the inner column names, separated by names_sep
.
names_repair
Used to check that output data frame has valid
names. Must be one of the following options:
"minimal
": no name repair or checks, beyond basic existence,
"unique
": make sure names are unique and not empty,
"check_unique
": (the default), no name repair, but check they are unique,
"universal
": make the names unique and syntactic
a function: apply custom name repair.
tidyr_legacy: use the name repair from tidyr 0.8.
a formula: a purrr-style anonymous function (see rlang::as_function()
)
See vctrs::vec_as_names()
for more details on these terms and the
strategies used to enforce them.
.drop,.preserve
:
all list-columns are now preserved; If there are any that you
don't want in the output use select()
to remove them prior to
unnesting.
.id
:
convert df %>% unnest(x, .id = "id")
to df %>% mutate(id = names(x)) %>% unnest(x))
.
.sep
:
use names_sep
instead.