Error in rep(1, n.ahead) : invalid ‘times’ argument in R

You need to specify the arguments to forecast() a little differently; since you didn’t post example data, I’ll demonstrate with the gold dataset in the forecast package: You may want to spend some time with the forecast package documentation to see what the arguments for the various functions are named and in what order they appear. Regarding your forecast.Arima not found error, you can see this answer to … Read more

Categories r

R – Concatenate two dataframes?

You want “rbind”. rbind requires the data frames to have the same columns. The first line adds column b to data frame b. Results

Categories r

data.table vs dplyr: can one do something well the other can’t or does poorly?

We need to cover at least these aspects to provide a comprehensive answer/comparison (in no particular order of importance): Speed, Memory usage, Syntax and Features. My intent is to cover each one of these as clearly as possible from data.table perspective. Note: unless explicitly mentioned otherwise, by referring to dplyr, we refer to dplyr’s data.frame interface whose internals are in … Read more

Categories r

Position-dodge warning with ggplot boxplot?

The number of groups is not the problem; I can see the same thing even when there are only 2 groups. The issue is that ggplot2 draws boxplots vertically (continuous along y, categorical along x) and you are trying to draw them horizontally (continuous along x, categorical along y). Also, your example has several syntax errors and … Read more

Error in model.frame.default: variable lengths differ

Joran suggested to first remove the NAs before running the model. Thus, I removed the NAs, run the model and obtained the residuals. When I updated model2 by inclusion of the lagged residuals, the error message did not appear again. Remove NAs Run the main model Obtain residuals Update model2 by including the lag 1 … Read more

Categories r

Aggregate multiple columns at once

We can use the formula method of aggregate. The variables on the ‘rhs’ of ~ are the grouping variables while the . represents all other variables in the ‘df1’ (from the example, we assume that we need the mean for all the columns except the grouping), specify the dataset and the function (mean). Or we can use summarise_each from dplyr after grouping (group_by) Or using summarise with across (dplyr devel version … Read more