# Help file for the class of Date objects: help(Dates) # Help file for converting Date objects using as.Date: help(as.Date) # Example of a series of dates: dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92") is.character(dates) dates.of.interest <- as.Date(dates, "%m/%d/%y") dates.of.interest weekdays(dates.of.interest) diff(dates.of.interest) # number of days between the dates todays.date <- Sys.Date() # formatting today's date with month as a word: format(todays.date, "%d %b %Y") # Some more dates in character form: more.dates <- c("1jan1960", "2jan1960", "31mar1960", "30jul1960") # Converting to Date format: dates.long.ago <- as.Date(more.dates, "%d%b%Y") # Note that the capital Y was needed for # the four-digit representation of year. # Reading the football data: football.dfr<-as.data.frame(scan("http://people.stat.sc.edu/hitchcock/football_data.txt",sep=',',skip=1, what=list(game.date='character',visitor.team='character',visitor.score=0, home.team='character',home.score=0),multi.line=T)) attach(football.dfr) game.date <- as.Date(as.character(game.date), "%m/%d/%Y") # The as.character() is necessary to convert game.date to a character object # It had been changed to a factor when the data frame was created wk.day <- weekdays(game.date) football.dfr <- cbind(wk.day, football.dfr) football.dfr ?DateTimeClasses