1

I'd like to know how can I summarize (in r code) that object by year and by month and convert in a ts object to make forecast:

My object calls v, and has three columns

Price year month     

241.        2016  Sep  
252.        2016  Sep  
252.        2016  Sep  
262.        2016  Sep  
267.        2016  Sep  
250.        2016  Sep  
246.        2016  Sep  
250.        2016  Sep  
257.        2016  Sep  
269.        2016  Sep  
# ... with 1,143 more rows

class(v)

[1] "tbl_df"     "tbl"        "data.frame"

I'd like put in ts object the means values of prices by year and by month this:

     Jan Fev Mar May....Nov Dez

2016

2017

2018

Thanks for all.

Wil
  • 3,076
  • 2
  • 12
  • 31
  • 1
    have you read the [documentation](https://www.rdocumentation.org/packages/stats/versions/3.5.3/topics/ts) for `ts()` and attempted to apply it to your data? – Wil Apr 08 '19 at 03:38
  • sounds more like a long -> wide question. Look here: https://stackoverflow.com/questions/5890584/how-to-reshape-data-from-long-to-wide-format – Wimpel Apr 08 '19 at 05:49
  • @Wimpel I’m not sure that’s the case. `ts` is a specific class in R. Its print method prints with months horizontal and years vertical, but it appears the OP is more concerned with creating a `ts` object than simply achieving that shape. – Wil Apr 08 '19 at 09:43
  • Thanks for the documentation @Wimpel, actually the most important is summarize the dataset like a "ts" or some document when i use the function ts I get that my goal matrix. – Wecsley Prates Apr 08 '19 at 14:43

0 Answers0