Essentially this is a wrapper around gather that is able to bind_cols with several gather operations. This is useful when a wide data frame contains uncertainty or flag information in paired columns.

parallel_gather(x, key, ..., convert = FALSE, factor_key = FALSE)

Arguments

x

A data.frame

key

Column name to use to store variables, which are the column names of the first gather operation.

...

Named arguments in the form new_col_name = c(old, col, names). All named arguments must have the same length (i.e., gather the same number of columns).

convert

Convert types (see gather)

factor_key

Control whether the key column is a factor or character vector.

Value

A gathered data frame.

See also

Examples

# gather paired value/error columns using # parallel_gather parallel_gather(pocmajsum, key = "param", value = c(Ca, Ti, V), sd = c(Ca_sd, Ti_sd, V_sd))
#> core depth param value sd #> 1 MAJ-1 0 Ca 1884.66667 452.354212 #> 2 MAJ-1 1 Ca 1418.00000 NA #> 3 MAJ-1 2 Ca 1550.00000 NA #> 4 MAJ-1 3 Ca 1448.00000 NA #> 5 MAJ-1 4 Ca 1247.00000 NA #> 6 MAJ-1 5 Ca 1412.33333 125.894135 #> 7 POC-2 0 Ca 1622.00000 508.766155 #> 8 POC-2 1 Ca 1488.00000 NA #> 9 POC-2 2 Ca 2416.00000 NA #> 10 POC-2 3 Ca 2253.00000 NA #> 11 POC-2 4 Ca 2372.00000 NA #> 12 POC-2 5 Ca 2635.33333 143.039622 #> 13 MAJ-1 0 Ti 2369.66667 401.056521 #> 14 MAJ-1 1 Ti 2409.00000 NA #> 15 MAJ-1 2 Ti 2376.00000 NA #> 16 MAJ-1 3 Ti 2485.00000 NA #> 17 MAJ-1 4 Ti 2414.00000 NA #> 18 MAJ-1 5 Ti 1897.33333 81.291656 #> 19 POC-2 0 Ti 2038.00000 608.303378 #> 20 POC-2 1 Ti 2016.00000 NA #> 21 POC-2 2 Ti 3270.00000 NA #> 22 POC-2 3 Ti 3197.00000 NA #> 23 POC-2 4 Ti 3536.00000 NA #> 24 POC-2 5 Ti 3890.00000 45.177428 #> 25 MAJ-1 0 V 78.33333 9.237604 #> 26 MAJ-1 1 V 70.00000 NA #> 27 MAJ-1 2 V 70.00000 NA #> 28 MAJ-1 3 V 64.00000 NA #> 29 MAJ-1 4 V 57.00000 NA #> 30 MAJ-1 5 V 81.00000 11.789826 #> 31 POC-2 0 V 33.00000 5.291503 #> 32 POC-2 1 V 36.00000 NA #> 33 POC-2 2 V 79.00000 NA #> 34 POC-2 3 V 79.00000 NA #> 35 POC-2 4 V 87.00000 NA #> 36 POC-2 5 V 87.00000 7.549834
# identical result using only tidyverse functions library(dplyr) library(tidyr) gathered_values <- pocmajsum %>% select(core, depth, Ca, Ti, V) %>% gather(Ca, Ti, V, key = "param", value = "value") gathered_sds <- pocmajsum %>% select(core, depth, Ca_sd, Ti_sd, V_sd) %>% gather(Ca_sd, Ti_sd, V_sd, key = "param_sd", value = "sd") bind_cols( gathered_values, gathered_sds %>% select(sd) )
#> core depth param value sd #> 1 MAJ-1 0 Ca 1884.66667 452.354212 #> 2 MAJ-1 1 Ca 1418.00000 NA #> 3 MAJ-1 2 Ca 1550.00000 NA #> 4 MAJ-1 3 Ca 1448.00000 NA #> 5 MAJ-1 4 Ca 1247.00000 NA #> 6 MAJ-1 5 Ca 1412.33333 125.894135 #> 7 POC-2 0 Ca 1622.00000 508.766155 #> 8 POC-2 1 Ca 1488.00000 NA #> 9 POC-2 2 Ca 2416.00000 NA #> 10 POC-2 3 Ca 2253.00000 NA #> 11 POC-2 4 Ca 2372.00000 NA #> 12 POC-2 5 Ca 2635.33333 143.039622 #> 13 MAJ-1 0 Ti 2369.66667 401.056521 #> 14 MAJ-1 1 Ti 2409.00000 NA #> 15 MAJ-1 2 Ti 2376.00000 NA #> 16 MAJ-1 3 Ti 2485.00000 NA #> 17 MAJ-1 4 Ti 2414.00000 NA #> 18 MAJ-1 5 Ti 1897.33333 81.291656 #> 19 POC-2 0 Ti 2038.00000 608.303378 #> 20 POC-2 1 Ti 2016.00000 NA #> 21 POC-2 2 Ti 3270.00000 NA #> 22 POC-2 3 Ti 3197.00000 NA #> 23 POC-2 4 Ti 3536.00000 NA #> 24 POC-2 5 Ti 3890.00000 45.177428 #> 25 MAJ-1 0 V 78.33333 9.237604 #> 26 MAJ-1 1 V 70.00000 NA #> 27 MAJ-1 2 V 70.00000 NA #> 28 MAJ-1 3 V 64.00000 NA #> 29 MAJ-1 4 V 57.00000 NA #> 30 MAJ-1 5 V 81.00000 11.789826 #> 31 POC-2 0 V 33.00000 5.291503 #> 32 POC-2 1 V 36.00000 NA #> 33 POC-2 2 V 79.00000 NA #> 34 POC-2 3 V 79.00000 NA #> 35 POC-2 4 V 87.00000 NA #> 36 POC-2 5 V 87.00000 7.549834