I am using the following code to give me the day of the week from a date (in the form dd/mm/yyyy).
Edit: I have uploaded a more relvant dataset.
df <- structure(list(Date = c("18/01/2013", "18/01/2013", "18/01/2013",
"18/01/2013", "18/01/2013"), Time = c("07:25:30", "07:25:40",
"07:25:50", "07:26:00", "07:26:10"), Axis1 = c(217L, 320L, 821L,
18L, 40L), Steps = c(6L, 7L, 5L, 1L, 1L), wday = c(7, 7, 7, 7, 7)), .Names = c("Date", "Time", "Axis1", "Steps", "wday"), row.names = 18154:18158, class = "data.frame")
library(lubridate)
df$wday = wday(df$Date)
df$wday.name = wday(df$Date, label = TRUE, abbr = TRUE)
The 18/1 was however a Friday and not a Saturday as R reports.
Does anyone have any suggestions of how to rectify this?
EDIT: I tried to follow the suggestions given by Dirk...
as.POSIXlt(df[,1])$wday
... but this still implies that the 18/1 is a Saturday.
My timezone is GMT/UTC (+ 1 for British Summer Time), however because I just want R to read from the date column (which is just d/m/y), I presume I don't need to specify this...
How can I get a correct wday column to be added to my existing R dataframe? (as detailed previously in my original script). I am struggling to get the suggested coding working as I gave the dataframe in the wrong format - apologies.