Hi,
I think that there is something that I am misunderstanding in creating tables
using dates that are of class POSIXct. Consider:
> x <- data.frame(date = as.POSIXct(strptime(c(rep("2002-10-17", 4), rep("1999-12-08",
> 2)), format = "%Y-%m-%d")))
> x
date
1 2002-10-17
2 2002-10-17
3 2002-10-17
4 2002-10-17
5 1999-12-08
6 1999-12-08
> table(x$date)
944629200 1034827200
2 4
I understand that the headings here are the number of seconds since some
epoch. But shouldn't the values print out here as they print out in the
dataframe?
I can get the effect that I want using:
> table(format(x$date))
1999-12-08 2002-10-17
2 4
The problem is that this can add a lot of time to the calculation in big
dataframes.
> x <- data.frame(date = as.POSIXct(strptime(c(rep("2002-10-17", 40000),
> rep("1999-12-08", 20000)), format = "%Y-%m-%d")))
> dim(x)
[1] 60000 1
> system.time(table(x$date))
> [1] 0.19 0.00 0.19 0.00 0.00
> system.time(table(format(x$date)))
[1] 18 0 19 0 0
Am I missing something?
> R.version
_
platform sparc-sun-solaris2.6
arch sparc
os solaris2.6
system sparc, solaris2.6
status
major 1
minor 6.2
year 2003
month 01
day 10
language R
>
Thanks,
Dave Kane
______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help