This function folds values of a many to one relationship together in a single character composed of comma separated values.

collapse_rows(df, group_by_var, many_mapping_col)

Arguments

df

dataframe, tibble, The data structure to work on

group_by_var

tidy-eval, character The variable to group by

many_mapping_col

The column of values that will collapse into a list.

Value

The inputs pasted together as a character string.

Details

The inputs can be anything that can be input into the paste function.

Examples


#example data 
nodes_tot=data.frame(
 FirstName=sample(c('A','B','C'),size = 50,replace=TRUE),
 LastName=sample(c('1','2','3'),size = 50,replace=TRUE),
 Latitude=sample(c('D','E','F'),size = 50,replace=TRUE),
 Longitude=sample(c('4','5','6'),size = 50,replace=TRUE))
#---------

collapse_rows(nodes_tot,FirstName,Longitude)
#> # A tibble: 3 × 4
#> # Groups:   FirstName [3]
#>   FirstName ls        wot   pretty_col
#>   <chr>     <list>    <lgl> <chr>     
#> 1 A         <chr [3]> FALSE 5, 4, 6   
#> 2 B         <chr [3]> FALSE 6, 5, 4   
#> 3 C         <chr [2]> FALSE 5, 6