I am all new to r programming and wanted to know if there is any way to create a function in R, which reads the day of the week and assigns 1 if it is a weekend and 0 if it is a weekday.
I have converted the date type in character format to date type and have created month, year, day, dayoftheweek, hour and min columns. I now want to create a column 'Weekend/Weekday' with 0 and 1 value.
I have used wday function so 1 is for Sunday and 7 for Saturday. If wday is 1 and 7, assign value 1 or else 0.
weekend = function(n)
if (n$Wday == 1 || n$Wday == 7)
return 1
else
return 0