[R] Need help with R date handling and barchart with errorbars
Mulholland, Tom
Tom.Mulholland at dpi.wa.gov.au
Fri Apr 22 03:45:31 CEST 2005
Fristly when you are using a package (in this case date) put it in your email.
Dates are stored as numbers and if I recall correctly as.date will be the number of days since sometime in 1960. As with other objects there are generally methods that will ensure that the correct printed format will occur. So what that means is that packages that are aware of date or it's methods will print formatted dates. In other cases however you will be required to do that formatting for that package. Since I don't use date I can't tell you how prevalent support is.
So barplot(table(testdata$date)) gives you the numeric format
while barplot(table(date.mmddyy(testdata$date))) gives you the mmddyy format
I don't know about lattice but I know that in the past I've had issues using dates (POISX in particular) but a lot of work has gone in over the past year (which is how long it is since I used the package) and I think these things are handled much better than they were. I think getting stuck in and checking the list for dates and lattice will give you enough starting points such as http://finzi.psych.upenn.edu/R/Rhelp02a/archive/45948.html. I'm sure there are more.
Tom
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Ghosh, Sandeep
> Sent: Friday, 22 April 2005 6:45 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Need help with R date handling and barchart with
> errorbars
>
>
> Hi All..
>
> Have a question.. For the following r code
>
> testdata <- as.data.frame(t(structure(c(
> "1/1/04","LV1",3.8,2,87,
> "2/1/04","LV1",3.2,3,28,
> "3/1/04","LV1",3.4,3,88,
> "4/1/04","LV1",3,2,26,
> "5/1/04","LV1",3.8,2,87,
> "6/1/04","LV1",3.2,3,28,
> "7/1/04","LV1",3.4,3,88,
> "8/1/04","LV1",3,2,26,
> "9/1/04","LV1",3.8,2,87,
> "10/1/04","LV1",3.2,3,28,
> "11/1/04","LV1",3.4,3,88,
> "12/1/04","LV1",3,2,26,
> "1/1/05","LV1",3.8,2,87,
> "2/1/05","LV1",3.2,3,28,
> "3/1/05","LV1",3.4,3,88,
> "4/1/05","LV1",3,2,26
> ), .Dim=c(5,16))));
> colnames(testdata) <- c('date','dataset','mean','stdDev','miceCount');
> testdata[c("date")] <- lapply(testdata[c("date")],
> function(x) as.date(levels(x)[x]));
> testdata[c("mean")] <- lapply(testdata[c("mean")],
> function(x) as.numeric(levels(x)[x]));
>
> On trying to print the data frame
> >testdata
>
> I get this..
>
> date dataset mean stdErr miceCount
> 1 -20454 LV1 3.8 2 87
> 2 -20423 LV1 3.2 3 28
> 3 -20394 LV1 3.4 3 88
> 4 -20363 LV1 3.0 2 26
> 5 -20333 LV1 3.8 2 87
> 6 -20302 LV1 3.2 3 28
> 7 -20272 LV1 3.4 3 88
> 8 -20241 LV1 3.0 2 26
> 9 -20210 LV1 3.8 2 87
> 10 -20180 LV1 3.2 3 28
> 11 -20149 LV1 3.4 3 88
> 12 -20119 LV1 3.0 2 26
> 13 -20088 LV1 3.8 2 87
> 14 -20057 LV1 3.2 3 28
> 15 -20029 LV1 3.4 3 88
> 16 -19998 LV1 3.0 2 26
>
> where as when I run this
> >dates <- c(lapply(testdata[c("date")], function(x)
> as.date(levels(x)[x])));
>
> the ouput is
> $date
> [1] 1Jan4 1Feb4 1Mar4 1Apr4 1May4 1Jun4 1Jul4 1Aug4 1Sep4
> 1Oct4 1Nov4 1Dec4
> [13] 1Jan5 1Feb5 1Mar5 1Apr5
>
> Question:
> 1. Can someone please explain me why the difference.
>
> 2. I later want to plot the data using barchart eg
> (barchart(date ~ mean | dataset, data=testdata);) in which
> case will the dates appear in assending order of dates or
> something special needs to be done for that.
>
> 3. Also I'll really appreciate if anyone can tell me if
> there's a way to get stdErrorBars on charts that are drawn
> using barchart function in lattice package.
>
> Any help or advise is greatly appreciated...
>
> Thanks,
> Sandeep.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list