Linear Regression Model Not running Gives Error

Just wanted to thank you for all your help on this I know you did not have to do this

Try it on the original data, before you make it a factor.

For this I should open up a new script

Yes, open a new script and read in the data again from scratch.

Looks like the Data reads in as a factor

from my own research, I tried this code

levels(RData2019$Day)

Got this result

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

Brought in a new script

Code
distinct(RData2019$Day)

Error
no applicable method for 'distinct' applied to an object of class "character"

Ran This code got

class(RData2019$Day)

RData2019$Day

Got this back in Console

class(RData2019$Day)
[1] "character"

RData2019$Day
[1] "Thursday" "Saturday" "Sunday" "Monday"
[5] "Tuesday" "Wednesday" "Friday" "Sunday"
[9] "Monday" "Tuesday" "Wednesday" "Friday"
[13] "Saturday" "Sunday" "Tuesday" "Wednesday"
[17] "Friday" "Saturday" "Sunday" "Friday"
[21] "Saturday" "Sunday" "Monday" "Tuesday"
[25] "Wednesday" "Thursday" "Friday" "Saturday"
[29] "Sunday" "Tuesday" "Wednesday" "Thursday"
[33] "Friday" "Saturday" "Saturday" "Sunday"
[37] "Monday" "Tuesday" "Wednesday" "Thursday"
[41] "Friday" "Saturday" "Sunday" "Tuesday"
[45] "Wednesday" "Thursday" "Thursday" "Friday"
[49] "Saturday" "Sunday" "Tuesday" "Wednesday"
[53] "Tuesday" "Wednesday" "Friday" "Saturday"
[57] "Sunday" "Thursday" "Friday" "Saturday"
[61] "Sunday" "Monday" "Tuesday" "Tuesday"
[65] "Wednesday" "Thursday" "Friday" "Saturday"
[69] "Sunday" "Tuesday" "Wednesday" "Thursday"
[73] "Friday" "Saturday" "Sunday" "Tuesday"
[77] "Wednesday" "Thursday" "Friday" "Saturday"
[81] "Sunday"

I will admit to being puzzled. I don't see why the labels had 81 values when there are only 7 unique character strings.

For little clarification, if this might help each day does have a different attendance attached to it also this has not been changed to a factor yet in that cod day is still character

If I'm reading correctly, there are only 81 lines in the data. If that's right, you might read in a clean copy of the data and then use dput() to make text that you can copy and paste here. What's going on is something of a mystery to me and if you post the data someone might be able to spot the problem.

Note that distinct works on data frames, not on vectors (which is what RData2019$Day is). For example, this works since we're passing a data frame and a column name:

> distinct(starwars, hair_color)
# A tibble: 13 × 1
   hair_color   
   <chr>        
 1 blond        
 2 NA           
 3 none         
 4 brown        
 5 brown, grey  
 6 black        
 7 auburn, white
 8 auburn, grey 
 9 white        
10 grey         
11 auburn       
12 blonde       
13 unknown      

However, this does not work since we're passing a vector:

> distinct(starwars$hair_color)
Error in UseMethod("distinct") : 
  no applicable method for 'distinct' applied to an object of class "character"

If you want the unique values within a vector, use unique:

> unique(starwars$hair_color)
 [1] "blond"         NA              "none"          "brown"         "brown, grey"  
 [6] "black"         "auburn, white" "auburn, grey"  "white"         "grey"         
[11] "auburn"        "blonde"        "unknown"      

This topic was automatically closed 7 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.