2 codes, same logic but one doesn't work

why this code works :> unique(hotel_bookings$hotel)
and this doesnt:
gh ← hotel_bookings %>%
unique(hotel)

dataset link: /kaggle/input/hotel-booking/hotel_booking.csv

unique is a base R function.

If you want the tidyverse approach (your second code with the %>% pipe), you should use distinct() instead of unique.

2 Likes

So pipe operators cannot be used for base r functions?

I’m new to this so I don’t have much idea about this language.

Base R has its native pipe, which is |>

Here you have an explanation of the Differences between the base R and magrittr pipes: Differences between the base R and magrittr pipes

Hope that helps!