tidyverse

Error casted by simple mutate using tidyverse or dplyr

别来无恙 提交于 2019-12-21 20:43:22
问题 I am having serious troubles using the tidyverse package that I cannot debug. As an example, "mutate" does not work properly even on past project I have already produced. This all started when I installed the following package: library(pdftools) library(tm) library(stringi) library(tidyverse) (or library(dplyr) library(tidyr)) library(purrr) ) And it still remains when I do a rm(list=ls()) . The only thing I haven't tried so forth is deinstalling R/RStudio and reinstalling it. I use RStudio

Save a data frame with list-columns as csv file

我与影子孤独终老i 提交于 2019-12-21 14:59:35
问题 I have the following data frame that looks like this (3 columns as list). A tibble: 14 x 4 clinic_name drop_in_hours appointment_hours services <chr> <list> <list> <list> 1 Birth Control and Sexual Health Centre <list [1]> <list [1]> <list [1]> 2 Black Creek Community Health Centre (Sheridan Mall Site) <list [1]> <list [1]> <list [1]> 3 Black Creek Community Health Centre (Yorkgate mall Site) <list [1]> <list [1]> <list [1]> 4 Crossways Clinic <list [1]> <list [1]> <list [1]> 5 Hassle Free

How to convert fitdistrplus::fitdist summary into tidy format?

元气小坏坏 提交于 2019-12-21 04:59:25
问题 I have the following code: x <- c( 0.367141764080875, 0.250037975705769, 0.167204185003365, 0.299794433447383, 0.366885973041269, 0.300453205296379, 0.333686861081341, 0.33301168850398, 0.400142004893329, 0.399433677388411, 0.366077304765104, 0.166402979455671, 0.466624230750293, 0.433499934139897, 0.300017278751768, 0.333673696762895, 0.29973685692478 ) fn <- fitdistrplus::fitdist(x,"norm") summary(fn) #> Fitting of the distribution ' norm ' by maximum likelihood #> Parameters : #> estimate

Evaluation Error when tidyverse is loaded after Hmisc

折月煮酒 提交于 2019-12-21 04:07:09
问题 I am using r 3.3.3, dplyr 0.7.4, and Hmisc 4.1-1. I noticed that the order I load packages effects whether or not a dplyr::summaries function wold work or not. I understand that loading packages in a different order would mask certain functions but I am using the package::function() syntax to avoid that issue. The exact issue revolves around labeled variables. I know that there has been issues in the past with tidyverse and variable labels but none seem to address why this particular

Use filter() (and other dplyr functions) inside nested data frames with map()

走远了吗. 提交于 2019-12-21 03:55:26
问题 I'm trying to use map() of purrr package to apply filter() function to the data stored in a nested data frame. "Why wouldn't you filter first, and then nest? - you might ask. That will work (and I'll show my desired outcome using such process), but I'm looking for ways to do it with purrr . I want to have just one data frame, with two list-columns, both being nested data frames - one full and one filtered. I can achieve it now by performing nest() twice: once on all data, and second on

How to fork/parallelize process in purrr::pmap

若如初见. 提交于 2019-12-20 14:40:08
问题 I have the following code that does serial processing with purr::pmap library(tidyverse) set.seed(1) params <- tribble( ~mean, ~sd, ~n, 5, 1, 1, 10, 5, 3, -3, 10, 5 ) params %>% pmap(rnorm) #> [[1]] #> [1] 4.373546 #> #> [[2]] #> [1] 10.918217 5.821857 17.976404 #> #> [[3]] #> [1] 0.2950777 -11.2046838 1.8742905 4.3832471 2.7578135 How can I parallelize (fork) the process above so that it runs faster and produces identical result? Here, I use rnorm for illustration purpose, in reality I have

Passing string variable to forcats::fct_reorder

笑着哭i 提交于 2019-12-20 06:12:28
问题 Any idea how to pass a string sorting variable to fct_reorder ? require(dplyr) require(forcats) require(ggplot2) order_var = 'displ' mpg %>% mutate(manufacturer = fct_reorder(manufacturer, order_var)) #> Error in mutate_impl(.data, dots): Evaluation error: length(f) == length(.x) is not TRUE. Tried with bang bang !! : mpg %>% mutate(manufacturer = fct_reorder(manufacturer, !!order_var)) #> Error in mutate_impl(.data, dots): Evaluation error: length(f) == length(.x) is not TRUE. Tried with

Column name of last non-NA row per row; using tidyverse solution?

▼魔方 西西 提交于 2019-12-20 03:43:21
问题 Brief Dataset description: I have survey data generated from Qualtrics, which I've imported into R as a tibble. Each column corresponds to a survey question, and I've preserved the original column order (to correspond with the order of the questions in the survey). Problem in plain language: Due to normal participant attrition, not all participants completed all of the questions in the survey. I want to know how far each participant got in the survey, and the last question they each answered

Pivot wider produces nested object

拈花ヽ惹草 提交于 2019-12-20 03:31:55
问题 This is regarding latest tidyr release. I am trying pivot_wider & pivot_longer function from library(tidyr) (Update 1.0.0) I was trying to obtain normal iris dataset when I run below but instead I get nested sort of 3X5 dimension tibble, not sure whats happening (I read https://tidyr.tidyverse.org/articles/pivot.html) but still not sure how to avoid this library(tidyr) iris %>% pivot_longer(-Species,values_to = "count") %>% pivot_wider(names_from = name, values_from = count) Expected Output:

tidyr::gather multiple columns of varying types

馋奶兔 提交于 2019-12-20 02:28:27
问题 My question is similar to this question. I'm trying to tidyr::gather multiple columns. However, the solution provided in the link is less than ideal because the attributes are generally not identical across all columns and so they are dropped. Note, I know how to do this with base R, but I'm trying to learn how to do the equivalent operation with tidyr and/or dplyr. Below I've simulated some data (poorly, but quickly) that illustrate the situation I often find myself in (although I generally