1

I believe this may have been asked a lot, but I have data in the format below and I can't apply the existing answers to my questions (including this nearest answer - R - Stock market data from csv to xts).

Date,AX,BY,CZ
5/21/2015,817,57,22.55
5/22/2015,810.5,57.45,22.7

So the data is in the format of DATE, CLOSE of stock AX, CLOSE of stock BY, CLOSE of stock CZ. Just to specify, the date is in the format shown above that is, m/d/YYYY where months and days are flexible in digits (one or two) while year is always in the format of four digits. The file is saved as CSV.

I wanted to use this code to convert the "zoo" read data to xts.

x <- as.xts(z)

The xts and zoo vignettes aren't really newbie friendly, so I hope someone can give a little nudge.

Community
  • 1
  • 1
  • I would really appreciate if you could help identify the places where the vignettes are not new-user-friendly, and provide suggestions for how to improve them. It's really hard for developers to write documentation that is easy for new users to understand, because the developers know the code so well. – Joshua Ulrich May 23 '16 at 13:22

1 Answers1

1

You might look at the examples in the help page for read.zoo. You need to tell the function about the header, the date format, and the separator between values. To read the data from a text string would look like

library(xts)
z <- read.zoo(header=TRUE, format="%m/%d/%Y", sep=",",
               text ="Date,AX,BY,CZ
                      5/21/2015,817,57,22.55
                      5/22/2015,810.5,57.45,22.7")
z <- as.xts(z)

To read from the file fileName, replace text=... with file="filename".

WaltS
  • 5,410
  • 2
  • 18
  • 24