Creating xts objects from csv file

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating xts objects from csv file

reichmaj
R-Help Forum

 

Starting to work with xts objects but can't figure out what I'm doing wrong
when converting *.csv file with a dtg variable to a *.xts object. When I'm
converting to an appropriate time object all I get are NA, so that's my
first issue.

 

dtg <- c("1/5/2010 2:30", "1/5/2010 10:32", "1/5/2010 12:03")

seq <- c(1,2,3)

 

dat <- data.frame(dtg, seq)

 

dat$dtg <- as.POSIXlt(dat$dtg, format = "%m/%d/%Y %H:%M")

 

dat.xts <- xts(x = dat[,-1], order.by = dat[,1])

               

head(dat.xts)


        [[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: Creating xts objects from csv file

John Kane-3
Are you sure you loaded the xts library?

On Mon, 20 Jul 2020 at 16:32, Jeff Reichman <[hidden email]> wrote:

> R-Help Forum
>
>
>
> Starting to work with xts objects but can't figure out what I'm doing wrong
> when converting *.csv file with a dtg variable to a *.xts object. When I'm
> converting to an appropriate time object all I get are NA, so that's my
> first issue.
>
>
>
> dtg <- c("1/5/2010 2:30", "1/5/2010 10:32", "1/5/2010 12:03")
>
> seq <- c(1,2,3)
>
>
>
> dat <- data.frame(dtg, seq)
>
>
>
> dat$dtg <- as.POSIXlt(dat$dtg, format = "%m/%d/%Y %H:%M")
>
>
>
> dat.xts <- xts(x = dat[,-1], order.by = dat[,1])
>
>
>
> head(dat.xts)
>
>
>         [[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.
>


--
John Kane
Kingston ON Canada

        [[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.