Dear Oren,
Try this:

> x <- data.frame(A= c("X", "Y", "X", "X", "Y", "Y", "Z" ), D =
+ as.POSIXct(c("2008-11-03","2008-11-03","2008-11-03", "2008-11-04",
+ "2009-01-13", "2009-01-13", "2009-01-13")), Z = 1:7)
>
> m<-with(x,tapply(Z, list(A,D), sum))
> m[rownames(m)==x$A[1],]
2008-11-03 2008-11-04 2009-01-13
         4          4         NA
> m[,colnames(m)==x$D[1]]
 X  Y  Z
 4  2 NA
> m[rownames(m)==x$A[1],colnames(m)==x$D[1]]
[1] 4
> x$A[1]
[1] X
Levels: X Y Z
> x$D[1]
[1] "2008-11-03 EST"

See ?with, ?tapply, ?rownames, and ?colnames for more information.

HTH,

Jorge


On Wed, Mar 4, 2009 at 6:22 PM, oren cheyette <ocheyette@gmail.com> wrote:

> Trying to use dates in their R-native form (e.g., POSIXct) rather than
> turning them into character strings, I've encountered the following
> problem.
> I create a data frame where one column is dates. Then I use "by()" to do a
> calculation on grouped subsets of the data. When I try to extract values
> from the result, I get "subscript out of bounds". The example below shows
> the error.
>
> > x <- data.frame(A= c("X", "Y", "X", "X", "Y", "Y", "Z" ), D =
> as.POSIXct(c("2008-11-03","2008-11-03","2008-11-03", "2008-11-04",
> "2009-01-13", "2009-01-13", "2009-01-13")), Z = 1:7)
> > m <- by(x, list(A=x$A, D=x$D), function(v) { sum(v$Z); })
> > m[x$A[1], x$D[1]]
> Error: subscript out of bounds
>
>
> Rgds,
> Oren Cheyette
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

	[[alternative HTML version deleted]]


