I don't understand why R gives me a warning about "Longer object length is not a multiple of shorter object length"

I have this object which is generated by doing an aggregate over an xts series giving the weekday median:

```
u <- aggregate(d, list(Ukedag = format(index(d),"%w")), median)
1 314.0
2 282.5
3 270.0
4 267.0
5 240.5
```

Then I try to apply this to my original xts series, which looks like this (only a lot longer)

```
head(d)
2009-01-02 116
2009-01-05 256
2009-01-06 286
```

Using:

```
coredata(d) <- coredat(d) - u[format(index(d),"%w")];
```

Which results in a warning.

The intent is to subtract the weekday mean. It appears to work despite the warning, but what should I worry about?

```
apply.daily(d, function(x) coredata(x) - u[format(index(x), "%w")] )
```

I did indeed have a serious error. This doesn't give any warnings and I tested it by doing:

```
apply.daily(d, function(x) u[format(index(x), "%w")] )
```

Then checking some dates, and it appeared that is was in alignment with the calendar.

Yes, this is something that you should worry about. Check the length of your objects with nrow(). R can auto-replicate objects so that they're the same length if they differ, which means you might be performing operations on mismatched data.

In this case you have an obvious flaw in that your subtracting aggregated data from raw data. These will definitely be of different lengths. I suggest that you merge them as time series (using the dates), then locf(), then do your subtraction. Otherwise merge them by truncating the original dates to the same interval as the aggregated series. Just be very careful that you don't drop observations.

Lastly, as some general advice as you get started: look at the result of your computations to see if they make sense. You might even pull them into a spreadsheet and replicate the results.

- How to get AIC from Conwayâ€“Maxwell-Poisson regression via COM-poisson package in R?
- R : how to simply repeat a command?
- session not created: This version of ChromeDriver only supports Chrome version 74 error with ChromeDriver Chrome using Selenium
- How to show code but hide output in RMarkdown?
- remove kernel on jupyter notebook
- Function to calculate R2 (R-squared) in R
- Center Plot title in ggplot2
- R ggplot2: stat_count() must not be used with a y aesthetic error in Bar graph
- R multiple conditions in if statement
- What does "The following object is masked from 'package:xxx'" mean?
- Saving a high resolution image in R
- Change bar plot colour in geom_bar with ggplot2 in r
- Converting data frame column from character to numeric
- Extract Month and Year From Date in R
- How to combine two lists in R
- Extract year from date
- Ifelse statement in R with multiple conditions
- R dplyr: Drop multiple columns
- Remove legend ggplot 2.2
- Remove all of x axis labels in ggplot
- how to remove multiple columns in r dataframe?
- Aggregate multiple columns at once
- Changing fonts in ggplot2
- How to specify "does not contain" in dplyr filter
- how to use the Box-Cox power transformation in R
- Convert dataframe column to 1 or 0 for "true"/"false" values and assign to dataframe
- Having trouble setting working directory
- Coerce multiple columns to factors at once
- How to declare a vector of zeros in R
- Create empty data frame with column names by assigning a string vector?
- Explain ggplot2 warning: "Removed k rows containing missing values"
- R for loop skip to next iteration ifelse
- Error: package or namespace load failed for ggplot2 and for data.table
- How do I change the default library path for R packages
- Select first and last row from grouped data
- R * not meaningful for factors ERROR
- Error: could not find function "%>%"
- Raise to power in R
- In R, dealing with Error: ggplot2 doesn't know how to deal with data of class numeric
- Error - replacement has [x] rows, data has [y]
- Merge r brings error "'by' must specify uniquely valid columns"
- Non-numeric Argument to Binary Operator Error in R
- Convert row names into first column
- Append data frames together in a for loop
- Plotting with ggplot2: "Error: Discrete value supplied to continuous scale" on categorical y-axis
- R Markdown - changing font size and font type in html output
- Replace all occurrences of a string in a data frame
- How to convert dataframe into time series?
- Sum across multiple columns with dplyr
- Removing NA observations with dplyr::filter()
- [Move to Longer object length is not a multiple of shorter object length?]