I have an xts object which I have split into months using split(data, "months"). This splits my data into months of each year. I want to group my data into months regardless of the year thanks.
Asked
Active
Viewed 858 times
1
-
1Please share sample of your data using `dput()` (not `str` or `head` or picture/screenshot) so others can help. See more here https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example?rq=1 – Tung Jul 06 '18 at 05:04
-
maybe something like `split(data, format(index(data), "%m"))` ? – chinsoon12 Jul 06 '18 at 06:00
1 Answers
0
require(lubridate) # we will use the month() function
# basically extracts the month from a date
split(data, month(as.Date(data)))
# your code, with as.Date() we make sure it's the correct format

RLave
- 8,144
- 3
- 21
- 37
-
3While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Ralf Stubner Jul 06 '18 at 11:30