tidyverse

R: Forecasting multiple time series with fable, tsibble and map

与世无争的帅哥 提交于 2020-06-29 06:50:29
问题 I am trying to fit some time series using the R packages tsibble and fable , the still-under-construction replacement for the redoubtable Rob Hyndman's forecast package. The series are all combined into one tsibble, which I then fit with ARIMA, a function which replaces, among other things, forecast::auto.arima . I use map_at , first to iterate over all the elements except the Date , and then again to extract the model information from the models that have been fit to each series using

R: Forecasting multiple time series with fable, tsibble and map

我的梦境 提交于 2020-06-29 06:50:01
问题 I am trying to fit some time series using the R packages tsibble and fable , the still-under-construction replacement for the redoubtable Rob Hyndman's forecast package. The series are all combined into one tsibble, which I then fit with ARIMA, a function which replaces, among other things, forecast::auto.arima . I use map_at , first to iterate over all the elements except the Date , and then again to extract the model information from the models that have been fit to each series using

Dunnett's test that is compatible with the tidyverse in R?

北城以北 提交于 2020-06-29 04:08:22
问题 I see when I run library(multcomp) (see this example), it complains (among other things): Attaching package: ‘MASS’ The following object is masked from ‘package:dplyr’: select Masking select is going to be awkward. I suppose I can use multcomp without putting it into the namespace with library . EDIT : What is the easiest way to run Dunnett's test that works well with the tidyverse? (Old question: Is there another package that offers Dunnett's test that is more compatible with the tidyverse?)

Heatwave calculation based on maximum temperature in R

强颜欢笑 提交于 2020-06-28 07:14:12
问题 A heatwave is defined if the maximum temperature at a meteorological station is 3 °C or more than the normal temperature consecutively for 3 days or more (Adopted from India Meteorological Department, Pune). I have calculated the daily average (daily normal) from multiple-year daily maximum temperature data like df <- data.frame("date"= seq(from = as.Date("1970-1-1"), to = as.Date("2000-12-31"), by = "day"), "MaxT" = runif(length(seq.Date(as.Date("1970-1-1"), as.Date("2000-12-31"), "days")),

rlang, fpp3 R package: Error: `vars` must be a character vector upon calling aggregate_key()

╄→尐↘猪︶ㄣ 提交于 2020-06-28 06:40:29
问题 I'm working through the Hyndman fpp3 package based on this markdown document. https://github.com/robjhyndman/ISI_Workshop_2019/blob/master/5_reconciliation/reconciliation.Rmd I just couldn't find out why the following code fail to run PBS %>% aggregate_key(ATC1/ATC2, Scripts = sum(Scripts)) %>% filter(Month == yearmonth("1991 Jul")) %>% print(n=18) I keep receiving the following error each time I run the above. New names: * `` -> ...1 * `` -> ...2 * `` -> ...3 * `` -> ...4 * `` -> ...5 * ...

How do you calculate row and column totals on a tibble using tidyverse functions [duplicate]

回眸只為那壹抹淺笑 提交于 2020-06-28 05:01:22
问题 This question already has answers here : Add row to a data frame with total sum for each column (9 answers) Closed 18 days ago . Given an n by m tibble with numeric values. How do you calculate row and column totals for the tibble. Here is a reprex with a sample tibble: library(tidyverse) df <- tibble(names=c('a','b','c','d','e'),x = 1:5, y =5:1, z=2:6) df #> # A tibble: 5 x 4 #> names x y z #> <chr> <int> <int> <int> #> 1 a 1 5 2 #> 2 b 2 4 3 #> 3 c 3 3 4 #> 4 d 4 2 5 #> 5 e 5 1 6 Created on

How to reference a column in a nested dataframe (then use purrr::map)

喜夏-厌秋 提交于 2020-06-27 04:15:11
问题 I have a very simple question about referencing data columns within a nested dataframe. For a reproducible example, I'll nest mtcars by the two values of variable am : library(tidyverse) mtcars_nested <- mtcars %>% group_by(am) %>% nest() mtcars_nested which gives data that looks like this. #> # A tibble: 2 x 2 #> # Groups: am [2] #> am data #> <dbl> <list> #> 1 1 <tibble [13 × 10]> #> 2 0 <tibble [19 × 10]> If I now wanted to use purrr::map to take the mean of mpg for each level of am I

How to reference a column in a nested dataframe (then use purrr::map)

混江龙づ霸主 提交于 2020-06-27 04:14:05
问题 I have a very simple question about referencing data columns within a nested dataframe. For a reproducible example, I'll nest mtcars by the two values of variable am : library(tidyverse) mtcars_nested <- mtcars %>% group_by(am) %>% nest() mtcars_nested which gives data that looks like this. #> # A tibble: 2 x 2 #> # Groups: am [2] #> am data #> <dbl> <list> #> 1 1 <tibble [13 × 10]> #> 2 0 <tibble [19 × 10]> If I now wanted to use purrr::map to take the mean of mpg for each level of am I

Summary Statistics table with factors and continuous variables

萝らか妹 提交于 2020-06-27 03:55:07
问题 I am trying to create a simple summary statistics table (min, max, mean, n, etc) that handles both factor variables and continuous variables, even when there is more than one factor variable. I'm trying to produce good looking HTML output, eg stargazer or huxtable output. For a simple reproducible example, I'll use mtcars but change two of the variables to factors, and simplify to three variables. library(tidyverse) library(stargazer) mtcars_df <- mtcars mtcars_df <- mtcars_df %>% mutate(vs =

Applying mutate_at conditionally to specific rows in a dataframe in R

别等时光非礼了梦想. 提交于 2020-06-23 04:11:09
问题 I have a dataframe in R that looks like the following: a b c condition 1 4 2 acap 2 3 1 acap 2 4 3 acap 5 6 8 ncap 5 7 6 ncap 8 7 6 ncap I am trying to recode the values in columns a, b, and c for condition ncap (and also 2 other conditions not pictured here) while leaving the values for acap alone. The following code works when applied to the first 3 columns. I am trying to figure out how I can apply this only to rows that I specify by condition while keeping everything in the same dataframe