jadoo
jadoo

Reputation: 11

R programming , split time series date

I just have a data file with one column of time series:

'2012-02-01 17:42:44'                       
'2012-02-01 17:42:44'          
'2012-02-01 17:42:44'

data.frame(table(cut(MyDates, breaks = c("week", "hours")))

After converting the the column to as.POSIXct , i'm trying to create a frequency table by weeks and hours of a day
This code does not work.

Please suggest?

Upvotes: 1

Views: 288

Answers (1)

G. Cocca
G. Cocca

Reputation: 2541

The right argument to use is breaks = "hour" (check ?cut.POSIXt)

MyDates<-read.table(text= "2012-02-01 17:42:44
                            2012-02-01 17:42:44         
                            2012-02-01 17:42:44",
                    header = F, sep = "_", 
                    col.names = "date")

# convet to class POSIXct
MyDates <- as.POSIXct(MyDates$date)

# your frequency tables
hours <- table(cut(MyDates, breaks = "hour"))
weeks <- table(cut(MyDates, breaks = "week"))

Upvotes: 2

Related Questions