I'd use xts::ndays
library(xts)
ndays(data)
But if you don't want to load another package, you could just do this
length(unique(as.Date(time(data))))
문제
My data looks like this guy below.
> head(data)
open high low close
2013-06-20 09:31:00 275.50 276.00 275.08 275.65
2013-06-20 09:32:00 275.61 276.88 275.61 276.67
2013-06-20 09:33:00 276.67 276.72 275.95 276.62
2013-06-20 09:34:00 276.48 277.43 276.27 277.00
2013-06-20 09:35:00 277.00 278.00 277.00 278.00
2013-06-20 09:36:00 277.83 277.97 276.58 277.29
I get the number of unique days by typing in this:
length(levels(as.factor(floor(as.numeric(julian(index(data)))))))
Is there a better way to do this? I wish there was a numdays.zoo() function or something.
해결책
I'd use xts::ndays
library(xts)
ndays(data)
But if you don't want to load another package, you could just do this
length(unique(as.Date(time(data))))
다른 팁
You can transform you index to day format and use table
:
table(format(index(data),'%y-%m-%d'))
13-06-20
6
Then number of days is for example :
length(names(table(format(index(data),'%y-%m-%d'))))