Skip to contents

Splits a column with 2 comma-separated fields into two columns.

Usage

split_double_col(d, nms)

Arguments

d

Input tibble data.

nms

A character vector of columns to split.

Value

A modified tibble with the original columns averaged and split nicely.

Examples

x <- tibble::tibble(
  a = letters[1:11],
  b = c("0.4,0.8", paste0(round(runif(10), 2), ",", round(runif(10), 2))),
  nacol = rep(NA, 11),
  namix = sample(c(NA, "0.4,0.6"), 11, replace = TRUE)
)
(b <- gpgr:::split_double_col(x, "b"))
#> # A tibble: 11 × 1
#>    b                
#>    <chr>            
#>  1 0.6 (0.4, 0.8)   
#>  2 0.48 (0.08, 0.87)
#>  3 0.5 (0.83, 0.17) 
#>  4 0.32 (0.6, 0.03) 
#>  5 0.24 (0.16, 0.32)
#>  6 0.21 (0.01, 0.4) 
#>  7 0.33 (0.47, 0.2) 
#>  8 0.45 (0.5, 0.4)  
#>  9 0.17 (0.29, 0.06)
#> 10 0.56 (0.73, 0.39)
#> 11 0.88 (0.77, 0.98)
(nacol <- gpgr:::split_double_col(x, "nacol"))
#> # A tibble: 11 × 1
#>    nacol
#>    <chr>
#>  1 NA   
#>  2 NA   
#>  3 NA   
#>  4 NA   
#>  5 NA   
#>  6 NA   
#>  7 NA   
#>  8 NA   
#>  9 NA   
#> 10 NA   
#> 11 NA   
(namix <- gpgr:::split_double_col(x, "namix"))
#> # A tibble: 11 × 1
#>    namix         
#>    <chr>         
#>  1 NA            
#>  2 NA            
#>  3 0.5 (0.4, 0.6)
#>  4 NA            
#>  5 NA            
#>  6 NA            
#>  7 0.5 (0.4, 0.6)
#>  8 NA            
#>  9 0.5 (0.4, 0.6)
#> 10 0.5 (0.4, 0.6)
#> 11 NA