rowwise: Group input by rows

Description Usage Arguments Details Examples

Description

\Sexpr[results=rd, stage=render]{dplyr:::lifecycle("questioning")}

Usage

1

Arguments

data

Input data frame.

Details

See this repository for alternative ways to perform row-wise operations

rowwise() is used for the results of do() when you create list-variables. It is also useful to support arbitrary complex operations that need to be applied to each row.

Currently, rowwise grouping only works with data frames. Its main impact is to allow you to work with list-variables in summarise() and mutate() without having to use [[1]]. This makes summarise() on a rowwise tbl effectively equivalent to plyr::ldply().

Examples

1
2
3
4
df <- expand.grid(x = 1:3, y = 3:1)
df_done <- df %>% rowwise() %>% do(i = seq(.$x, .$y))
df_done
df_done %>% summarise(n = length(i))

Example output

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

Source: local data frame [9 x 1]
Groups: <by row>

# A tibble: 9 x 1
          i
*    <list>
1 <int [3]>
2 <int [2]>
3 <int [1]>
4 <int [2]>
5 <int [1]>
6 <int [2]>
7 <int [1]>
8 <int [2]>
9 <int [3]>
# A tibble: 9 x 1
      n
  <int>
1     3
2     2
3     1
4     2
5     1
6     2
7     1
8     2
9     3

dplyr documentation built on July 4, 2019, 5:08 p.m.