tidyverse

Many regressions using tidyverse and broom: Same dependent variable, different independent variables

ぐ巨炮叔叔 提交于 2021-02-08 04:49:33
问题 This link shows how to answer my question in the case where we have the same independent variables, but potentially many different dependent variables: Use broom and tidyverse to run regressions on different dependent variables. But my question is, how can I apply the same approach (e.g., tidyverse and broom) to run many regressions where we have the reverse situation: same dependent variables but different independent variable. In line with the code in the previous link, something like: mod

Stop text labels from overlapping in ggplot2

和自甴很熟 提交于 2021-02-08 03:54:27
问题 So I have a dataframe like so df <- structure(list(Reportable = c("A", "B", "A", "B", "A", "B", "A", "B", "A", "B", "A", "B", "A", "B" ), Location1_Description = c("MAIN/BRANCH", "MAIN/BRANCH", "YARD", "YARD", "PART", "PART", "SHOP", "SHOP", "LOT", "LOT", "HIGHWAY/ROADWAY", "HIGHWAY/ROADWAY", "OFFICE", "OFFICE" ), count = c(146L, 447L, 83L, 241L, 44L, 89L, 38L, 83L, 16L, 28L, 4L, 30L, 11L, 21L), pct = c("25%", "75%", "26%", "74%", "33%", "67%", "31%", "69%", "36%", "64%", "12%", "88%", "33%",

Stop text labels from overlapping in ggplot2

允我心安 提交于 2021-02-08 03:48:53
问题 So I have a dataframe like so df <- structure(list(Reportable = c("A", "B", "A", "B", "A", "B", "A", "B", "A", "B", "A", "B", "A", "B" ), Location1_Description = c("MAIN/BRANCH", "MAIN/BRANCH", "YARD", "YARD", "PART", "PART", "SHOP", "SHOP", "LOT", "LOT", "HIGHWAY/ROADWAY", "HIGHWAY/ROADWAY", "OFFICE", "OFFICE" ), count = c(146L, 447L, 83L, 241L, 44L, 89L, 38L, 83L, 16L, 28L, 4L, 30L, 11L, 21L), pct = c("25%", "75%", "26%", "74%", "33%", "67%", "31%", "69%", "36%", "64%", "12%", "88%", "33%",

Stop text labels from overlapping in ggplot2

非 Y 不嫁゛ 提交于 2021-02-08 03:48:07
问题 So I have a dataframe like so df <- structure(list(Reportable = c("A", "B", "A", "B", "A", "B", "A", "B", "A", "B", "A", "B", "A", "B" ), Location1_Description = c("MAIN/BRANCH", "MAIN/BRANCH", "YARD", "YARD", "PART", "PART", "SHOP", "SHOP", "LOT", "LOT", "HIGHWAY/ROADWAY", "HIGHWAY/ROADWAY", "OFFICE", "OFFICE" ), count = c(146L, 447L, 83L, 241L, 44L, 89L, 38L, 83L, 16L, 28L, 4L, 30L, 11L, 21L), pct = c("25%", "75%", "26%", "74%", "33%", "67%", "31%", "69%", "36%", "64%", "12%", "88%", "33%",

programming a filter in tidyverse using quoting

血红的双手。 提交于 2021-02-07 21:31:08
问题 I have a tibble with paired variables: - a_x, a_y, - b_x, b_y, - c_x, c_y and so on. How can I write a function that filters depending on "a", "b" or "c". For instance I want to return filter(df, a_x != a_y) or filter(df, b_x != b_y) I'm using quosures, as described in https://dplyr.tidyverse.org/articles/programming.html, but without success. This is the example: test <-tribble(~a_x, ~b_x, ~a_y, ~b_y, 1,2,1,2, 5,6,5,8, 9,8,11,8) # that works x <-quo(a_x) y <-quo(a_y) filter(test, !!x == !!y)

Error while loading tidyverse in RStudio

こ雲淡風輕ζ 提交于 2021-02-07 20:31:49
问题 When trying to load the tidyverse package in RStudio, I get the following error message: library(tidyverse) Error: package or namespace load failed for ‘tidyverse’: .onAttach failed in attachNamespace() for 'tidyverse', details: call: NULL error: Function getThemeInfo not found in RStudio 回答1: I found that upgrading RStudio to version 1.1.383 resolved the problem for me, while still running the latest version of tidyverse. 回答2: I had the same issue, and wolfgang's answer solved it. I used the

Magrittr forward pipe fails to forward values into openXL::addWorksheet - “Error …: First argument must be a Workbook”

强颜欢笑 提交于 2021-02-07 20:27:14
问题 magrittr appears to be failing to pipe 'workbook' class objects into the addWorkbook function from the package openxlsx . ( Never mind why I need to use excel...eugh yuk ) For example, to write the InsectSprays dataset to an excel file in 'base' syntax: library("openxlsx") insect.wb <- createWorkbook() addWorksheet(wb = insect.wb, sheetName = "Insect Spray") writeData(wb = insect.wb, sheet = "Insect Spray", x= InsectSprays) openXL(insect.wb) Opens a temp excel file with the data. So magrittr

tidyverse: Cross tables of one variable with all other variables in data.frame

独自空忆成欢 提交于 2021-02-07 19:06:56
问题 I want to make cross table of a variable with all other variables in the data.frame. library(tidyverse) library(janitor) humans <- starwars %>% filter(species == "Human") humans %>% janitor::tabyl(gender, eye_color) gender blue blue-gray brown dark hazel yellow female 3 0 5 0 1 0 male 9 1 12 1 1 2 humans %>% dplyr::select_if(is.character) %>% dplyr::select(-name, -gender) %>% purrr::map(.f = ~janitor::tabyl(dat = humans, gender, .x)) Error: Unknown columns `blond`, `none`, `brown`, `brown,

How to detect if bare variable or string

南笙酒味 提交于 2021-02-07 13:51:06
问题 I am trying to write a plotting function where you can pass bare column names to select which columns are plotted. I would like also to be able to specify a string as the color. I have found that I need to use shQuote if I want to pass a string to aes_string. Now my problem is to figure out if a bare name or a string was passed. How would I do this? dat <- data.frame( time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")), total_bill = c(14.89, 17.23) ) plot_it <- function(dat, x,y,

Controlling decimal places displayed in a tibble. Understanding what pillar.sigfig does

与世无争的帅哥 提交于 2021-02-07 13:36:53
问题 I have a csv file weight.csv with the following contents. weight,weight_selfreport 81.5,81.66969147005445 72.6,72.59528130671505 92.9,93.01270417422867 79.4,79.4010889292196 94.6,96.64246823956442 80.2,79.4010889292196 116.2,113.43012704174228 95.4,95.73502722323049 99.5,99.8185117967332 If I do library(readr) Df <- read_csv('weight.csv') Df I get # A tibble: 9 x 2 weight weight_selfreport <dbl> <dbl> 1 81.5 81.7 2 72.6 72.6 3 92.9 93.0 4 79.4 79.4 5 94.6 96.6 6 80.2 79.4 7 116. 113. 8 95.4