This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Matrices do | |
@type permutation_map :: %{integer => integer} | |
@spec build_permutation(Enumerable.t()) :: permutation_map | |
def build_permutation(l) do | |
n = Enum.count(l) | |
Enum.zip(1..n, l) | |
|> Map.new() | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ms = function(.data, ...) { | |
dots = quos(...) | |
map(dots, ~ call_modify(., .data = .data) %>% eval_tidy()) %>% | |
reduce(function(tb1, tb2) { | |
for (newcol in setdiff(names(tb2), names(tb1))) { | |
tb1[[newcol]] = tb2[[newcol]] | |
} | |
tb1 | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to-do: properly document it | |
library(tidyverse) | |
library(rlang) | |
dummify = function(.data, ..., .pattern = "{column}_{value}") { | |
cols = quos(...) | |
new_cols = imap(cols, function(quoted_expr, column) { | |
if (is_integer(column) || column == "") { |