瀏覽代碼

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

occurrence
static
Maxime Wack 6 年之前
父節點
當前提交
f1826b18ea
共有 1 個文件被更改,包括 21 次插入4 次删除
  1. +21
    -4
      misc.R

+ 21
- 4
misc.R 查看文件

@@ -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…
取消
儲存