library(tidyverse)
mtcars %>% group_by(cyl) %>% is_grouped_df()
#> [1] TRUE
I can group a data frame by a variable and confirm if it is grouped using the is_grouped_df()
function (shown above).
I can run the same analysis on the dplyr rowwise()
function and it appears that rowwise()
does not group data sets by row. I have a question and a reading of the help page (?rowwise
) does not clearly answer the question for me.
Group input by rows
Description: rowwise() allows you to compute on a data frame a row-at-a-time. This is most useful when a vectorised function doesn't exist.
A row-wise tibble maintains its row-wise status until explicitly removed by group_by(), ungroup(), or as_tibble().
My question: After calling the rowwise()
function do I need to call the ungroup()
function later in my pipe to ungroup my data set? Or is this done by default? The following pipe suggests that a pipe containing rowwise()
is not grouped:
mtcars %>% rowwise() %>% is_grouped_df()
#> [1] FALSE
This sentence is confusing me, "A row-wise tibble maintains its row-wise status until explicitly removed by... ungroup()...". Why would I need to ungroup()
a tibble that is already ungrouped?
ungroup()
after callingrowwise()
in a pipe. This is assuming you want an ungrouped data set at the end of your pipe (which I do). – Display namestr(mtcars %>% group_by_all)
andstr(mtcars %>% rowwise())
, the group attributes for the variables are not seen inrowwise
– akrun