I'm brand new to R... I have a column in a data frame where I extracted the days of the week from a date-time column. I would like to add another column to show either "weekend" or "weekday". Where "Sat" and "Sun" return "weekend" and "Mon", "Tue", "Wed", "Thu", "Fri" return "weekday"
| day_of_week | wkend_wkday |
|---|---|
| Sat | |
| Mon | |
| Wed | |
| Sun | |
| Fri | |
| Tue | |
| Sat | |
| Wed | |
| Mon |
I have tried some ifelse() statements, but it doesn't seem to work.
Thank you!
You can use
%in%withifelseto check whether the day inday_of_weekcolumn matchesc("Sat", "Sun")vector. If it does,theifelsefunction returnsweekend. Otherwise, it returnsweekday. :