These functions work like tidyr::separate() and tidyr::unite(), combining information from multiple columns into single column. You can also create and separate columns using dplyr::mutate() and the constructors (geo_xy(), geo_segment(), and geo_rect()).

unite_xy(data, col, x, y, remove = TRUE)

separate_xy(data, col, into = c("x", "y"), remove = TRUE)

unite_xyz(data, col, x, y, z, remove = TRUE)

separate_xyz(data, col, into = c("x", "y", "z"), remove = TRUE)

unite_segment(data, col, x0, y0, x1, y1, remove = TRUE)

separate_segment(data, col, into = c("x0", "y0", "x1", "y1"), remove = TRUE)

unite_rect(data, col, xmin, ymin, xmax, ymax, remove = TRUE)

separate_rect(
  data,
  col,
  into = c("xmin", "ymin", "xmax", "ymax"),
  remove = TRUE
)

Arguments

data

A tibble::tibble() or data frame

col

A column name for the united object

x

x, y, and z coordinate vectors

y

x, y, and z coordinate vectors

remove

Use remove = FALSE to keep the source columns in the output.

into

Column names for the separated vectors

z

x, y, and z coordinate vectors

x0

Values for the start and end coordinates.

y0

Values for the start and end coordinates.

x1

Values for the start and end coordinates.

y1

Values for the start and end coordinates.

xmin

Border values, recycled to a common length using vctrs::vec_recycle_common().

ymin

Border values, recycled to a common length using vctrs::vec_recycle_common().

xmax

Border values, recycled to a common length using vctrs::vec_recycle_common().

ymax

Border values, recycled to a common length using vctrs::vec_recycle_common().

Value

data, with new column(s) col/into

Examples

tbl <- tibble(a = 1, b = 2, c = 3, d = 4) (united <- unite_xy(tbl, "xy", a, b))
#> # A tibble: 1 x 3 #> xy c d #> <xy> <dbl> <dbl> #> 1 (1 2) 3 4
separate_xy(united, xy)
#> # A tibble: 1 x 4 #> x y c d #> <dbl> <dbl> <dbl> <dbl> #> 1 1 2 3 4
(united <- unite_xyz(tbl, "xyz", a, b, c))
#> # A tibble: 1 x 2 #> xyz d #> <xyz> <dbl> #> 1 (1 2 3) 4
separate_xyz(united, xyz)
#> # A tibble: 1 x 4 #> x y z d #> <dbl> <dbl> <dbl> <dbl> #> 1 1 2 3 4
(united <- unite_rect(tbl, "rect", a, b, c, d))
#> # A tibble: 1 x 1 #> rect #> <rect> #> 1 (1 2...3 4)
separate_rect(united, rect)
#> # A tibble: 1 x 4 #> xmin ymin xmax ymax #> <dbl> <dbl> <dbl> <dbl> #> 1 1 2 3 4
# need to modify geo_segment() constructor! # (united <- unite_segment(tbl, "seg", a, b, c, d)) # separate_segment(united, seg)