This file contains hidden or 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
library(map) | |
library(rucrdtw) | |
map(list(first = 33, second = 19, third = 7), ~ ucred_mv(synthetic_control[-.x,], synthetic_control[.x,], byrow= TRUE)) %>% map_dbl("distance") %>% tibble::enframe(.) | |
# consider also adding this to that shiny app |
This file contains hidden or 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
library(dplyr) | |
library(tidyr) | |
words_some_missing <- data_frame(one_word = c(NA, "M", NA), | |
second_word = c("F", NA, NA)) | |
words_some_missing %>% | |
unite(sex, one_word, second_word) | |
## that sticks the NAs together, which I think is something you dont want? In |
This file contains hidden or 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
## this function will print "TRUE" if the categories defined by the vector are | |
## continuous, e.g. c("1500_20000","20000_NA","0_1500" ) ` | |
is_continuous_categories <- function(cat_vector){ | |
cat_range <- cat_vector %>% | |
str_split("_") %>% | |
transpose %>% | |
map(unlist) %>% | |
{c(invoke(setdiff, .), invoke(setdiff, rev(.)))} | |
identical(cat_range, c("0", "NA")) |
This file contains hidden or 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
matrix_to_df_firstline_header <- function(mat){ | |
requireNamespace("purrr") | |
mat %>% | |
## cut columns into lists | |
apply(2, function(s) list(s)) %>% | |
flatten %>% | |
map(flatten_chr) %>% | |
## set names to the first element of the list | |
{set_names(x = map(., ~ .x[-1]), |
This file contains hidden or 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
library(dplyr) | |
library(ggplot2) | |
dat <- data_frame(xs = runif(10, 2, 15), | |
ys = runif(10, 2, 15), | |
xe = rnorm(10, 2, 0.4), | |
ye = rnorm(10, 2, 0.4)) | |
dat %>% |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
library(purrr) | |
library(gapminder) | |
gapminder %>% | |
transpose %>% | |
map(~ splice(., totalgdp = .$pop * .$gdpPercap)) %>% | |
transpose %>% | |
simplify_all() %>% | |
as.data.frame() %>% | |
head |
This file contains hidden or 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
library(purrr) | |
library(gapminder) | |
gapminder %>% | |
transpose %>% | |
map(~ splice(., totalgdp = .$pop * .$gdpPercap)) %>% | |
transpose %>% | |
simplify_all() %>% | |
as.data.frame() %>% | |
head |