purrr

Programmatically create tab and plot in markdown

微笑、不失礼 提交于 2020-12-23 11:07:49
问题 I'm trying to create a dynamic number of tabs in my rmd with some content inside. This one doesn't help. Something like this: --- title: "1" output: html_document --- ```{r } library(highcharter) library(tidyverse) iris %>% dplyr::group_split(Species) %>% purrr::map(.,~{ # create tabset for each group ..1 %>% hchart("scatter", hcaes(x = Sepal.Length, y = Sepal.Width)) }) ``` 回答1: You can set results = 'asis' knitr option to generate the tabs in the map function using cat . Getting Highcharter

Programmatically create tab and plot in markdown

别来无恙 提交于 2020-12-23 11:05:13
问题 I'm trying to create a dynamic number of tabs in my rmd with some content inside. This one doesn't help. Something like this: --- title: "1" output: html_document --- ```{r } library(highcharter) library(tidyverse) iris %>% dplyr::group_split(Species) %>% purrr::map(.,~{ # create tabset for each group ..1 %>% hchart("scatter", hcaes(x = Sepal.Length, y = Sepal.Width)) }) ``` 回答1: You can set results = 'asis' knitr option to generate the tabs in the map function using cat . Getting Highcharter

R语言 基本统计分析

元气小坏坏 提交于 2020-12-15 01:58:15
“ 本章节是数据预处理的第一步:了解数据(集)。只有充分了解了数据,我们才能对数据做进一步的预处理和后续深入的分析。 ” 目录 1 数据结构 str() dim() head() 2 描述性统计分析 summary() psych::describe() 分组计算doBy::summaryBy 分组计算psych::describeBy 3 频数和列联表 table 一维计数 xtabs 多维(交叉)计数 gmodels::CrossTable #列联表 01 — 数据结构 严格来讲“数据结构”不是基本统计分析的内容,但是这是了解数据的第一步,因此这里做简单普及! 推荐使用str()函数 class() # 数据类型 dim() # 数据(集)的行列数 nrow() # 数据(集)的行数,等价于dim(mtcars)[1] ncol() # 数据(集)的列数,等价于dim(mtcars)[2] View() # 查看数据(集),以表格形式展示 如下图1 head(X,n) # 显示数据集前n行 str() # 查看数据(集)类型、行列数,每列的数据类型和简要数据概况 图1 View(mtcars) > data(mtcars) > class(mtcars) # 数据类型 [1] "data.frame" > dim(mtcars) # 数据(集)的行列数 [1] 32 11 >

fuzzy and exact match of two databases

∥☆過路亽.° 提交于 2020-12-13 03:40:13
问题 I have two databases. The first one has about 70k rows with 3 columns. the second one has 790k rows with 2 columns. Both databases have a common variable grantee_name . I want to match each row of the first database to one or more rows of the second database based on this grantee_name . Note that merge will not work because the grantee_name do not match perfectly. There are different spellings etc. So, I am using the fuzzyjoin package and trying the following: library("haven"); library(

fuzzy and exact match of two databases

时间秒杀一切 提交于 2020-12-13 03:38:25
问题 I have two databases. The first one has about 70k rows with 3 columns. the second one has 790k rows with 2 columns. Both databases have a common variable grantee_name . I want to match each row of the first database to one or more rows of the second database based on this grantee_name . Note that merge will not work because the grantee_name do not match perfectly. There are different spellings etc. So, I am using the fuzzyjoin package and trying the following: library("haven"); library(

How do I add a third dynamic list element to my pmap_dfc statement

和自甴很熟 提交于 2020-12-13 03:33:58
问题 I have the following working code that utilizes two lists to produce simulation output: strategy_list <- list("s_Win","s_WinH1", "s_WinH2", "s_WinH1F1", "s_WinH2F2", "s_WinDerEx") function_list <- list(s_win, s_winH1, s_winH2, s_winH1F1, s_winH2F2, s_winDerEx) l <- list(strategy_list, function_list) simulation <- pmap_dfc(l, ~ df %>% transmute(!! .x := .y(entries, skill, field, win_payoff, wager_amt, Winner, exacta_payoff))) %>% bind_cols(df, .) Now I would like to run the simulation at

printing ggplot with purrr map

戏子无情 提交于 2020-12-09 07:13:10
问题 I want to create ggplots for numeric cols against my response variable . Here is the reproducible code: test = mpg %>% select_if(is.numeric) %>% dplyr::select(-year) %>% nest(-cyl) %>% mutate(ggplots = map(data,~ggplot(data = .x) + geom_point(aes(x = cyl, y = .x)))) test # A tibble: 4 x 3 cyl data ggplots <int> <list<df[,3]>> <list> 1 4 [81 x 3] <gg> 2 6 [79 x 3] <gg> 3 8 [70 x 3] <gg> 4 5 [4 x 3] <gg> Warning message: All elements of `...` must be named. Did you want `data = c(displ, cty,

Split a dataframe into multilple dataframes by colums selection

心不动则不痛 提交于 2020-12-08 03:28:12
问题 These are my data frames: # data set.seed(1234321) # Original data frame (i.e. a questionnaire survey data) answer <- c("Yes", "No") likert_scale <- c("strongly disagree", "disagree", "undecided", "agree", "strongly agree") d1 <- c(rnorm(10)*10) d2 <- sample(x = c(letters), size = 10, replace = TRUE) d3 <- sample(x = likert_scale, size = 10, replace = TRUE) d4 <- sample(x = likert_scale, size = 10, replace = TRUE) d5 <- sample(x = likert_scale, size = 10, replace = TRUE) d6 <- sample(x =

Split a dataframe into multilple dataframes by colums selection

独自空忆成欢 提交于 2020-12-08 03:27:16
问题 These are my data frames: # data set.seed(1234321) # Original data frame (i.e. a questionnaire survey data) answer <- c("Yes", "No") likert_scale <- c("strongly disagree", "disagree", "undecided", "agree", "strongly agree") d1 <- c(rnorm(10)*10) d2 <- sample(x = c(letters), size = 10, replace = TRUE) d3 <- sample(x = likert_scale, size = 10, replace = TRUE) d4 <- sample(x = likert_scale, size = 10, replace = TRUE) d5 <- sample(x = likert_scale, size = 10, replace = TRUE) d6 <- sample(x =

Split a dataframe into multilple dataframes by colums selection

≯℡__Kan透↙ 提交于 2020-12-08 03:26:20
问题 These are my data frames: # data set.seed(1234321) # Original data frame (i.e. a questionnaire survey data) answer <- c("Yes", "No") likert_scale <- c("strongly disagree", "disagree", "undecided", "agree", "strongly agree") d1 <- c(rnorm(10)*10) d2 <- sample(x = c(letters), size = 10, replace = TRUE) d3 <- sample(x = likert_scale, size = 10, replace = TRUE) d4 <- sample(x = likert_scale, size = 10, replace = TRUE) d5 <- sample(x = likert_scale, size = 10, replace = TRUE) d6 <- sample(x =