[R] Help: Some problem with "gdata" package when using Dates
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Dec 18 15:09:28 CET 2008
Convert the date column to Date class and then
access that column, not the entire data frame:
> library(gdata)
> Dates <- read.xls("/tmp2/date.xls", header = FALSE)
Converting xls file to csv file... Done.
Reading csv file... Done.
> months(as.Date(Dates[[1]], "%m-%d-%y"))
[1] "December" "December" "January" "February" "June" "July"
"September"
On Thu, Dec 18, 2008 at 5:27 AM, Prabhanjan Tattar
<prabhanjannt at gmail.com> wrote:
> Dear List:
> I encountered this strange problem. I want to read dates in a R program.
> This is a sample data:
> Dates
> 12/12/08
> 14/12/08
> 18/01/08
> 28/02/08
> 16/06/08
> 19/07/08
> 28/09/08
>
> If I save these dates in a .csv file, and read it in R using "read.csv", I
> can perfectly read the data, and the commands "months(Dates)", "days(Dates)"
> work perfectly fine. On the other hand, if I save this data as an .xls file,
> and then read it in R using the "gdata" package using the command
> "read.xls("/.../.../Dates.xls",sheet=1,header=T)", and then attempt to read
> the months using months(Dates), this is the output that I get:
>> months(Dates)
> [1] Dec Dec Jan Mar Jun Jul Sep
> 12 Levels: Jan < Feb < Mar < Apr < May < Jun < Jul < Aug < Sep < ... < Dec
> The fourth observation is wrongly read as "Mar" whereas it should be read as
> "Feb". I am not able to make out the error. Am I making a mistake in reading
> the dates from the read.xls command?
> Thanks.
>
> --
> Prabhanjan N. Tattar
> Bangalore
>
>
> --
> Prabhanjan N. Tattar
> Lead Statistician
> CustomerXPS
> Bangalore
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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