[R] Need help with R date handling and barchart with errorbars

From: Ghosh, Sandeep <sghosh_at_lexgen.com>
Date: Fri 22 Apr 2005 - 08:44:41 EST


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@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 Received on Fri Apr 22 08:49:22 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:22 EST