arrange.temporal_cubble_df {cubble}R Documentation

dplyr methods

Description

Verbs supported for both nested and long cubble include: dplyr::mutate(), dplyr::filter(), dplyr::arrange(), dplyr::select(), dplyr::group_by(), dplyr::ungroup(), dplyr::summarise(),. dplyr::rename(), dplyr::bind_cols(), dplyr::rowwise(), dplyr::slice_*(), dplyr::*_join(), dplyr::relocate(), dplyr::pull()

Usage

## S3 method for class 'temporal_cubble_df'
arrange(.data, ...)

## S3 method for class 'spatial_cubble_df'
select(.data, ...)

## S3 method for class 'temporal_cubble_df'
select(.data, ...)

## S3 method for class 'spatial_cubble_df'
group_by(.data, ..., .add, .drop)

## S3 method for class 'temporal_cubble_df'
group_by(.data, ..., .add, .drop)

## S3 method for class 'spatial_cubble_df'
ungroup(x, ...)

## S3 method for class 'temporal_cubble_df'
ungroup(x, ...)

## S3 method for class 'spatial_cubble_df'
summarise(.data, ..., .by = NULL, .groups = NULL)

## S3 method for class 'temporal_cubble_df'
summarise(.data, ..., .by = key_vars(.data), .groups = NULL)

## S3 method for class 'spatial_cubble_df'
rename(.data, ...)

## S3 method for class 'temporal_cubble_df'
rename(.data, ...)

bind_rows.temporal_cubble_df(..., .id = NULL)

bind_cols.spatial_cubble_df(..., .name_repair)

bind_cols.temporal_cubble_df(..., .name_repair)

## S3 method for class 'spatial_cubble_df'
rowwise(data, ...)

## S3 method for class 'temporal_cubble_df'
rowwise(data, ...)

## S3 method for class 'cubble_df'
dplyr_col_modify(data, cols)

## S3 method for class 'spatial_cubble_df'
dplyr_row_slice(data, i, ...)

## S3 method for class 'temporal_cubble_df'
dplyr_row_slice(data, i, ...)

## S3 method for class 'spatial_cubble_df'
dplyr_reconstruct(data, template)

## S3 method for class 'temporal_cubble_df'
dplyr_reconstruct(data, template)

## S3 method for class 'spatial_cubble_df'
mutate(.data, ...)

## S3 method for class 'spatial_cubble_df'
filter(.data, ...)

## S3 method for class 'spatial_cubble_df'
arrange(.data, ...)

Arguments

...

In group_by(), variables or computations to group by. Computations are always done on the ungrouped data frame. To perform computations on the grouped data, you need to use a separate mutate() step before the group_by(). Computations are not allowed in nest_by(). In ungroup(), variables to remove from the grouping.

.add

When FALSE, the default, group_by() will override existing groups. To add to the existing groups, use .add = TRUE.

This argument was previously called add, but that prevented creating a new grouping variable called add, and conflicts with our naming conventions.

.drop

Drop groups formed by factor levels that don't appear in the data? The default is TRUE except when .data has been previously grouped with .drop = FALSE. See group_by_drop_default() for details.

x

A tbl()

.by

[Experimental]

<tidy-select> Optionally, a selection of columns to group by for just this operation, functioning as an alternative to group_by(). For details and examples, see ?dplyr_by.

.groups

[Experimental] Grouping structure of the result.

  • "drop_last": dropping the last level of grouping. This was the only supported option before version 1.0.0.

  • "drop": All levels of grouping are dropped.

  • "keep": Same grouping structure as .data.

  • "rowwise": Each row is its own group.

When .groups is not specified, it is chosen based on the number of rows of the results:

  • If all the results have 1 row, you get "drop_last".

  • If the number of rows varies, you get "keep" (note that returning a variable number of rows was deprecated in favor of reframe(), which also unconditionally drops all levels of grouping).

In addition, a message informs you of that choice, unless the result is ungrouped, the option "dplyr.summarise.inform" is set to FALSE, or when summarise() is called from a function in a package.

.id

The name of an optional identifier column. Provide a string to create an output column that identifies each input. The column will use names if available, otherwise it will use positions.

.name_repair

One of "unique", "universal", or "check_unique". See vctrs::vec_as_names() for the meaning of these options.

data, .data

a cubble object of class spatial_cubble_df or temporal_cubble_df

cols

A named list used to modify columns. A NULL value should remove an existing column.

i

A numeric or logical vector that indexes the rows of data.

template

Template data frame to use for restoring attributes.

Details

You may find not all the verbs have a verb.spatial_cubble_df or verb.temporal_cubble_df implemented. These verbs call the dplyr extending trios: dplyr_row_slice, dplyr_col_modify, and dplyr_reconstruct under the hood. See https://dplyr.tidyverse.org/reference/dplyr_extending.html

Examples

library(dplyr)
cb_nested <- climate_mel
cb_long <- face_temporal(climate_mel)

# filter - currently filter.spatial_cubble_df, dply_row_slice
cb_nested %>% filter(elev > 40)
cb_long %>% filter(prcp > 0)

# mutate - curerntly mutate.spatial_cubble_df, dply_col_modify
cb_nested %>% mutate(elev2 = elev + 10)
cb_long %>% mutate(prcp2 = prcp + 10)

# arrange - currently arrange.spatial_cubble_df, arrange.temporal_cubble_df
cb_nested %>% arrange(wmo_id)
cb_long %>% arrange(prcp)

# summarise - summarise.spatial_cubble_df,  summarise.temporal_cubble_df
cb_long %>%
  group_by(first_5 = ifelse(lubridate::day(date) <=5, 1, 2 )) %>%
  summarise(tmax = mean(tmax))
cb_long %>%
  mutate(first_5 = ifelse(lubridate::day(date) <=5, 1, 2)) %>%
  summarise(t = mean(tmax), .by = first_5)

# select -  select.spatial_cubble_df,  select.temporal_cubble_df
cb_nested %>% select(name)
cb_nested %>% select(-id, -name)
cb_long %>% select(prcp)
cb_long %>% select(-prcp, -date)

# rename - rename.spatial_cubble_df, rename.temporal_cubble_df
cb_nested %>% rename(elev2 = elev)
cb_long %>% rename(prcp2 = prcp)
# rename on key attributes
cb_nested %>% rename(id2 = id)
cb_long %>% rename(date2 = date)

# join - mutate_join - dplyr_reconstruct()
# join - filter_join - dplyr_row_slice()
df1 <- cb_nested %>% as_tibble() %>% select(id, name) %>% head(2)
nested <- cb_nested %>% select(-name)
nested %>% left_join(df1, by = "id")
nested %>% right_join(df1, by = "id")
nested %>% inner_join(df1, by = "id")
nested %>% full_join(df1, by = "id")
nested %>% anti_join(df1, by = "id")

# bind_rows - dplyr_reconstruct, bind_rows.temporal_cubble_df
df1 <- cb_nested %>% head(1)
df2 <- cb_nested %>% tail(2)
bind_rows(df1, df2)
df1 <- cb_long %>% head(10)
df2 <- cb_long %>% tail(20)
bind_rows(df1, df2)

# relocate - dplyr_col_select, dplyr_col_select
cb_nested %>% relocate(ts, .before = name)
cb_nested %>% face_temporal() %>% relocate(tmin)

# slice - all the slice_* uses dplyr::slice(), which uses dplyr_row_slice()
cb_nested %>% slice_head(n = 2)
cb_nested %>% slice_tail(n = 2)
cb_nested %>% slice_max(elev)
cb_nested %>% slice_min(elev)
cb_nested %>% slice_sample(n = 2)

# rowwise - rowwise.spatial_cubble_df, rowwise.temporal_cuble_df
cb_nested %>% rowwise()
cb_long %>% rowwise()

# group_by & ungroup -
(res <- cb_nested %>% mutate(group1 = c(1, 1, 2)) %>% group_by(group1))
res %>% ungroup()
(res2 <- res %>% face_temporal() %>% unfold(group1) %>% group_by(group1))
res2 %>% ungroup()
res2 %>% mutate(first_5 = ifelse(lubridate::day(date) <= 5, 1, 6)) %>%
  group_by(first_5) %>%
  ungroup(group1)

[Package cubble version 0.3.0 Index]