Skip to contents

For use with dplyr::summarise, for example

Usage

coalesce_rows(x)

Source

https://stackoverflow.com/questions/40515180/dplyr-how-to-find-the-first-non-missing-string-by-groups

Arguments

x

A vector

Value

A single value

Details

This function operates similarly to coalesce for columns, that is picking the first non-missing observation, but on observations rather than variables.

Examples

# \donttest{
dplyr::reframe(emperors$wikipedia, coalesce_rows(emperors$wikipedia))
#> # A tibble: 68 × 1
#>    ID       
#>    <chr>    
#>  1 Augustus 
#>  2 Tiberius 
#>  3 Caligula 
#>  4 Claudius 
#>  5 Nero     
#>  6 Galba    
#>  7 Otho     
#>  8 Vitellius
#>  9 Vespasian
#> 10 Titus    
#> # ℹ 58 more rows
coalesce_rows(emperors$wikipedia$Begin)
#> [1] "-0026-01-16"
# }