Mimics tidyr::unite using base R and rlang

b_unite(data, col, ..., sep = "_", remove = TRUE)

Arguments

data

data.frame

col

character, name of the new column

...

columns to combine

sep

character, separator to use between values, Default: '_'

remove

boolean, if TRUE remove input columns from output object, Default: TRUE

Value

data.frame

Details

the main difference between this lite version and the tidyr version is that the new column is attached to the end of the data.frame and not before the index of the first column that is to be united. Since this is mainly aesthetic it was not transfered over.

Examples

b_unite(airquality, col = "month_day", columns = c(Month,Day))%>% head
#> Ozone Solar.R Wind Temp month_day #> 1 41 190 7.4 67 5_1 #> 2 36 118 8.0 72 5_2 #> 3 12 149 12.6 74 5_3 #> 4 18 313 11.5 62 5_4 #> 5 NA NA 14.3 56 5_5 #> 6 28 NA 14.9 66 5_6
b_unite(airquality, col = "temp_month_day", columns = c(Temp:Day))%>% head
#> Ozone Solar.R Wind temp_month_day #> 1 41 190 7.4 67_5_1 #> 2 36 118 8.0 72_5_2 #> 3 12 149 12.6 74_5_3 #> 4 18 313 11.5 62_5_4 #> 5 NA NA 14.3 56_5_5 #> 6 28 NA 14.9 66_5_6
b_unite(airquality, col = "month_day", columns = c("Month","Day"))%>% head
#> Ozone Solar.R Wind Temp month_day #> 1 41 190 7.4 67 5_1 #> 2 36 118 8.0 72 5_2 #> 3 12 149 12.6 74 5_3 #> 4 18 313 11.5 62 5_4 #> 5 NA NA 14.3 56 5_5 #> 6 28 NA 14.9 66 5_6