shift_row_values: Shift row values left or right

Description Usage Arguments Value Examples

View source: R/shift_row_values.R

Description

Shift row values left or right

Usage

1
shift_row_values(.data, .dir = "left", at = NULL)

Arguments

.data

a table of data.

.dir

the shift direction as a string, one of "left" or "right".

at

the row indices at which to shift.

Value

a data frame.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
library(dplyr)
df <- tibble(
    s = c(NA, 1, NA, NA),
    t = c(NA, NA, 1, NA),
    u = c(NA, NA, 2, 5),
    v = c(5, 1, 9, 2),
    x = c(1, 5, 6, 7),
    y = c(NA, NA, 8, NA),
    z = 1:4
)
df %>% shift_row_values()
df %>% shift_row_values(at = 1:3)
df %>% shift_row_values(at = 1:2, .dir = "right")

Example output

Attaching package:dplyrThe following objects are masked frompackage:stats:

    filter, lag

The following objects are masked frompackage:base:

    intersect, setdiff, setequal, union

# A tibble: 4 x 7
      s     t     u     v     x     y     z
  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
1     5     1     1    NA    NA    NA    NA
2     1     1     5     2    NA    NA    NA
3     1     2     9     6     8     3    NA
4     5     2     7     4    NA    NA    NA
# A tibble: 4 x 7
      s     t     u     v     x     y     z
  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
1     5     1     1    NA    NA    NA    NA
2     1     1     5     2    NA    NA    NA
3     1     2     9     6     8     3    NA
4    NA    NA     5     2     7    NA     4
# A tibble: 4 x 7
      s     t     u     v     x     y     z
  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
1    NA    NA    NA    NA     5     1     1
2    NA    NA    NA     1     1     5     2
3    NA     1     2     9     6     8     3
4    NA    NA     5     2     7    NA     4

hacksaw documentation built on Jan. 13, 2021, 7:57 a.m.