Browse Source

Ajout paramètre "first" dans la fonction uniq() pour prendre la première

occurrence
static
Maxime Wack 6 years ago
parent
commit
f1826b18ea
1 changed files with 21 additions and 4 deletions
  1. +21
    -4
      misc.R

+ 21
- 4
misc.R View File

@@ -7,14 +7,31 @@ library(plotly)
library(forcats)
library(markdown)

uniq <- function(df, ...)
uniq <- function(df, ..., first = F)
{
uniq_vector <- function(x, fst)
{
x %>%
c %>%
rle %>%
.$lengths ->
l

if (fst)
{
l %>%
cumsum %>%
`-`(l) + 1
} else
{
l %>% cumsum
}
}

eval(substitute(alist(...))) %>%
map_chr(as.character) %>%
intersect(names(df)) %>%
map(~rle(df[[.x]] %>% c) %>%
.$lengths %>%
cumsum) %>%
map(~uniq_vector(df[[.x]], first)) %>%
reduce(union) %>%
sort -> columns



Loading…
Cancel
Save