I am trying to code weekends and weekdays using numeric values, such that "Monday","Tuesday",..."Friday" = 0 and "Saturday"/"Sunday" = 1. I presently have the following data:
head(bike.d)
Day Day.Code
Sunday 4
Sunday 4
Sunday 4
Sunday 4
Sunday 4
Sunday 4
tail(bike.d)
Day Day.Code
Saturday 3
Saturday 3
Saturday 3
Saturday 3
Saturday 3
Saturday 3
I have coded the Day column numerically using:
Day.Code = as.numeric(bike.d$Day)
Where Friday = 1, Monday = 2, Saturday = 3, Sunday = 4, Thursday = 5, Tuesday =6, Wednesday = 7.
I have tried to use logical operators to assign the binary values with weekdays =0 and weekends = 1. I have tried variations of the following argument, but I get the following output:
bike.d[,2 == 3|4]=1
head(bike.d)
Day Day.Code
1 1
1 1
1 1
1 1
1 1
1 1
tail(bike.d)
Day Day.Code
1 1
1 1
1 1
1 1
1 1
1 1
Is there a way I can create this argument so that the text values in the "Day" column is preserved? And so that the binary code is either input in the Day.code column, or a new column?
Thank you for your help!
merge
, it will make your life easier. – flodel