I got the code from a coursera course and don't know how to make it work. Any help would be greatly appreciated.
N.B. It was not an exam question, just a practice activity, thanks!
When getting an "object not found" error, the first thing to check if it exists. For a data frame, colnames does this
colnames(hotel_bookings)
and check for the variables hotel and market_segment. If they are, then the cause is probably that the dplyr library hasn't been loaded. Two ways to fix. Simplest
library(dplyr)
Alternatively,
dplyr::filter(hotel_bookings ...
There is a filter function in the {stats} library, which is loaded by default, so it's necessary to tell the script which to use. library(dplyr) does this by masking the {stats} function. dplyr::filter specifies the version to use.
When using {dplyr}, I prefer to write it left-to-right, starting with the data frame used as the input and ending up with the assignment to the new object