[R] Help with POSIXct
Bill.Venables at csiro.au
Bill.Venables at csiro.au
Mon Mar 21 23:43:51 CET 2011
You might try
dat$F1 <- format(as.Date(dat$F1), format = "%b-%y")
although it rather depends on the class of F1 as it has been read.
Bill Venables.
(It would be courteous of you to give us yor name, by the way.)
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of info at mathewanalytics.com
Sent: Tuesday, 22 March 2011 6:31 AM
To: r-help at r-project.org
Subject: [R] Help with POSIXct
I rarely work with dates in R, so I know very little about the
POSIXct and POSIXlt classes. I'm importing an excel file into R using
the RODBC package, and am having issues reformatting the dates.
1. The important info:
> sessionInfo()
R version 2.12.2 (2011-02-25)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United
States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RODBC_1.3-2
loaded via a namespace (and not attached):
[1] tools_2.12.2
2. My question:
My data looks like the following once it is imported into R.
one <- odbcConnectExcel("marketshare.xls")
dat <- sqlFetch(one, "Sheet1")
close(one)
> dat
F1 Marvel DC
1 2010-01-01 42 34
2 2010-02-01 45 34
3 2010-03-01 47 29
4 2010-04-01 45 32
5 2010-05-01 45 35
6 2010-06-01 42 34
Variable F1, is supposed to be Jan-10, Feb-10, Mar-10, etc.
However, in the process of importing the .xls file, R is reformating
the dates. How can I retrieve the original month-year format
that I have in my excel file.
3. While the R help list discourages against asking multiple questions in
an inquiry, it'd be really helpful if someone could point me to any good
online
resources on the POSIXct and POSIXlt classes.
______________________________________________
R-help at r-project.org mailing list
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.
More information about the R-help
mailing list