[R] Fwd: FW: Time Series

Eric Berger ericjberger at gmail.com
Tue Nov 7 10:53:45 CET 2017


[Please send replies to r-help, not individual  responders]
Emre,
In R, when you call a function defined via something like
f <- function( foo, bar )
then you can call it as, for, example

a <- f(x,y)

or

a <- f(foo=x, bar=y)

or even

a <- f( bar=y, foo=x)   # notice I switched the order!

The first approach requires you to pass the arguments in the same order as
the function is expecting.
In the second and third examples you can pass the arguments in any order
you want since you have indicated the variable names.
The point is that the variable name goes on the left of the '=' and the
values (or variables) you are passing go on the right of the '='.

The zoo function is defined as
zoo( x = NULL, order.by = index(x), etc ... )

In my example code I passed the variable 'mydata' to the parameter 'x' via

zoo(x=mydata, order.by=times)

If you called your local variable x then you can call zoo via

zoo(x=x, order.by=whatever)  # using the 'named parameters' approach

or

zoo(x, order.by=whatever)   # where zoo will match the first argument to
the first parameter in its definition.

Hopefully this will help you understand why some of your attempts worked
and some did not work.

Regards,
Eric



Hi Erin and Eric

As both of you suggested I followed the Erin’s command

It  is failed with the following command

when I wrote x , which is numeric vector. I says that unused argument.

tseri      <- zoo( x=mydata, order.by=times )



when use  it without x=mydata like,

tseri      <- zoo( x, order.by=times )



it works.

I checked it by following command

x[times==as.POSIXct("2015-12-18 02:00:00")] and it gave me the true value.



Do you think it is okay?



By the way, I appreciate for fast reply.

Thank you.



--
Emre



*From: *Eric Berger <ericjberger at gmail.com>
*Sent: *Tuesday, November 7, 2017 11:08 AM
*To: *Erin Hodgess <erinm.hodgess at gmail.com>
*Cc: *Emre Karagülle <karagullemre at gmail.com>; r-help at r-project.org
*Subject: *Re: [R] FW: Time Series



Following Erin's pointer:



library(zoo)
times     <- seq(from=as.POSIXct("2015-12-18 00:00:00"),
to=as.POSIXct("2017-10-24 23:00:00"), by="hour")
mydata <- rnorm(length(times))
tseri      <- zoo( x=mydata, order.by=times )



HTH,

Eric





On Tue, Nov 7, 2017 at 9:59 AM, Erin Hodgess <erinm.hodgess at gmail.com>
wrote:

Hello!

What is the error message, please?

At first glance, you are using the "ts" function.  That doesn't work for
hourly frequency.

You may want to create a zoo object.

This is Round One.

Sincerely,
Erin


On Tue, Nov 7, 2017 at 1:46 AM, Emre Karagülle <karagullemre at gmail.com>
wrote:


>
> Hi,
> I would like to ask a question about time series.
> I am trying to convert my data into time series data.
> I have hourly data from “2015-12-18 00:00” to “2017-10-24 23:00”
> I am trying the following codes but they are not working.
> Could you help me out?
>
> tseri <- ts(data ,seq(from=as.POSIXct("2015-12-18 00:00:00"),
> to=as.POSIXct("2017-10-24 23:00:00"), by="hour"))
>
> tseri <- ts(data ,seq(from=as.Date("2015-12-18 00:00:00"),
> to=as.Date("2017-10-24 23:00:00"), by="hour"))
>
>
> Thank you
>
> --
> Emre
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.



--
Erin Hodgess
Associate Professor
Department of Mathematical and Statistics
University of Houston - Downtown
mailto: erinm.hodgess at gmail.com


        [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org 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.

	[[alternative HTML version deleted]]



More information about the R-help mailing list