How to get the transpose of R´s function forecast output and turn it into a data frame

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get the transpose of R´s function forecast output and turn it into a data frame

PaulJr
Dear all,

Hope you are doing great. Some R time series functions generate the
forecasts in an horizontal way, for example:

                2017     2018     2019    2020
forecast    12           15        35        75

but I´d like to have the output as follows:


Date      forecast
2017           12
2018           15
2019           35
2020           75

I tried using the t() function to get the transpose, but after taking the
transpose I was not able to turn it into a data frame.

Any help will be greatly appreciated,

Cheers,

Paul

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to get the transpose of R´s function forecast output and turn it into a data frame

Peter Dalgaard-2
You're not giving us much to play with here. Reproducible example, please.

(Remember to send it to the list, not me.)

My immediate guess was cbind(), but without knowing the data structure, I can't tell for sure.

-pd

> On 16 Mar 2017, at 13:43 , Paul Bernal <[hidden email]> wrote:
>
> Dear all,
>
> Hope you are doing great. Some R time series functions generate the
> forecasts in an horizontal way, for example:
>
>                2017     2018     2019    2020
> forecast    12           15        35        75
>
> but I´d like to have the output as follows:
>
>
> Date      forecast
> 2017           12
> 2018           15
> 2019           35
> 2020           75
>
> I tried using the t() function to get the transpose, but after taking the
> transpose I was not able to turn it into a data frame.
>
> Any help will be greatly appreciated,
>
> Cheers,
>
> Paul
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to get the transpose of R´s function forecast output and turn it into a data frame

Jim Lemon-4
In reply to this post by PaulJr
Hi Paul,
As Peter noted, without knowing the structure of the the object, only
a guess can be made. Mine is:

fdf<-data.frame(Date=names(forecast),forecast=forecast)

You may want to apply as.numeric to the names.

Jim



On Thu, Mar 16, 2017 at 11:43 PM, Paul Bernal <[hidden email]> wrote:

> Dear all,
>
> Hope you are doing great. Some R time series functions generate the
> forecasts in an horizontal way, for example:
>
>                 2017     2018     2019    2020
> forecast    12           15        35        75
>
> but I´d like to have the output as follows:
>
>
> Date      forecast
> 2017           12
> 2018           15
> 2019           35
> 2020           75
>
> I tried using the t() function to get the transpose, but after taking the
> transpose I was not able to turn it into a data frame.
>
> Any help will be greatly appreciated,
>
> Cheers,
>
> Paul
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.