Calling out specific Levels in a factor to use in Model

Hello I have a data set here that brings in the Day of the week as character

I change the Vector to factor with two levels

levels(RData2019$Day)
[1] "Friday" "Saturday" "Sunday" "Monday"
[5] "Tuesday" "Wednesday" "Thursday"

I am trying to create a LM() with just Friday Saturday and Sunday as independent variables any clue on how to do this I have been searching for three days with know luck.

you have 7 levels not 2.
It seems like you want to remove rows of the dataframe RData2019 which have a day outiside of Saturday and Sunday; its popular on this forum to use dplyr::filter() for those sorts of operations; but this could be addressed with base R function subset

perhaps your best order of operations is to filter/subset reducing the frame to only the two types of rows of interest and then transform that dat column from character to factor, and it will naturally have 2 levels.

hello I am having some trouble getting this to work I truly do appreciate your help

here is the code I came up with, out of research

RData2019$Day <- as.factor(RData2019$Day)

filter(RData2019, Day == "monday", "Tuesday", "Wednesday", "Thursday")

this is the error I received
Error in filter():
! Problem while computing ..2 = "Tuesday".
:heavy_multiplication_x: Input ..2 must be a logical vector, not a character.
Run rlang::last_error() to see where the error occurred.

rlang:: last_error

  1. dplyr::filter(...)
  2. dplyr:::filter.data.frame(RData2019, Day == "monday", "Tuesday", "Wednesday",
    "Thursday")

in R we can contain together multiple items of the same type in a c(ombination) using c() or of mixed types in a list list().
Also filter is used to specify what is kept (the inverse of what is removed)

filter(RData2019, Day %in% c("Saturday","Sunday"))

Got the code to run but i do not think we achieved the result we were looking for

Code

filter(RData2019, Day %in% c("Friday","Saturday","Sunday"))

Result
Game Hour` Date COMP DOLLAR GROUP

1 2019-03-30 19:00:00 2019-03-30 00:00:00 NA 8 12544
2 2019-03-31 15:00:00 2019-03-31 00:00:00 8 11 4797
3 2019-04-12 19:00:00 2019-04-12 00:00:00 1 NA 1631
4 2019-04-14 14:00:00 2019-04-14 00:00:00 66 291 3657
5 2019-04-19 19:00:00 2019-04-19 00:00:00 12 8 4245
6 2019-04-20 19:00:00 2019-04-20 00:00:00 NA 14 4803
7 2019-04-21 14:00:00 2019-04-21 00:00:00 51 NA 611
8 2019-05-03 19:00:00 2019-05-03 00:00:00 NA NA 4932
9 2019-05-04 19:00:00 2019-05-04 00:00:00 14 15 4946
10 2019-05-05 14:00:00 2019-05-05 00:00:00 158 318 3493

… with 31 more rows, and 17 more variables: NGHTLY ,

SEASON , SINGLE , Day , OpeningDay ,

OpeningWeekend , PreASB , BOSNYY ,

Holiday , DayGame , WeekdayDayGame ,

Bobblehead , Wearable , OtherGiveaway ,

Kids , Concert , SpecEvent

:information_source: Use print(n = ...) to see more rows, and colnames() to see all variable names

Then I ran a check on the Variable to see if I only had Friday Saturday and Sunday Values left

Code:

RData2019$Day

Result
[1] Thursday Saturday Sunday Monday Tuesday
[6] Wednesday Friday Sunday Monday Tuesday
[11] Wednesday Friday Saturday Sunday Tuesday
[16] Wednesday Friday Saturday Sunday Friday
[21] Saturday Sunday Monday Tuesday Wednesday
[26] Thursday Friday Saturday Sunday Tuesday
[31] Wednesday Thursday Friday Saturday Saturday
[36] Sunday Monday Tuesday Wednesday Thursday
[41] Friday Saturday Sunday Tuesday Wednesday
[46] Thursday Thursday Friday Saturday Sunday
[51] Tuesday Wednesday Tuesday Wednesday Friday
[56] Saturday Sunday Thursday Friday Saturday
[61] Sunday Monday Tuesday Tuesday Wednesday
[66] Thursday Friday Saturday Sunday Tuesday
[71] Wednesday Thursday Friday Saturday Sunday
[76] Tuesday Wednesday Thursday Friday Saturday
[81] Sunday
7 Levels: Friday Monday Saturday Sunday ... Wednesday

Thank you for this. just as a reminder I am trying to isolate Friday, Saturday, and Sunday Values to see what
effect these independent days or variables would have on the model.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.