Skip to content

stuck on data

4 messages · Joshua Ulrich, Gabor Grothendieck, zubin

#
On Wed, Dec 24, 2008 at 4:56 PM, zubin <binabina at bellsouth.net> wrote:
You can use plot.xts, or plot.zoo (since xts extends zoo).
The See Also section of ?as.Date specifically references ?strptime for
how to specify date formats (the second argument to as.Date).  See the
Details section of ?strptime.
You don't say how you read the data into R.  Assuming you use
read.table, you need to set the argument stringsAsFactors = FALSE.
Then you could do something like:
x <- xts(DF, as.Date(DF[,"date"],"%d%b%Y"))  # Assuming your date
column is in that format
HTH,
Josh
--
http://quantemplation.blogspot.com
#
Assume the original file looked like this:

Lines <- "Store_nbr year month day date
177 2007 9 14 01APR2008
177 2007 9 14 01AUG2008"

# and you were given this data frame, DF:

DF <- read.table(textConnection(Lines), header = TRUE)

# then try this to plot Store_nbr

st <- read.zoo(DF, index.column = 5, format = "%d%b%Y")
plot(st$Store_nbr)

# or if you meant you were given the file, not DF directly:

library(zoo)
z <- read.zoo(textConnection(Lines), header = TRUE, index.column = 5,
	format = "%d%b%Y")
plot(z$Store_nbr)

See ?read.zoo, ?plot.zoo and the 3 zoo vignettes.  Also R News 4/1
has info on dates.
On Wed, Dec 24, 2008 at 5:56 PM, zubin <binabina at bellsouth.net> wrote: