How do I resolve error message for filtering toothgrowth?

I am on Google Professional Data Analytics course and in one of the online class, we have to analyse ToothGrowth dataset. However, I do not seem to have this dataset in R Studio Cloud. Does anyone know why is this so?

You need to load the dplyr package.

library(dplyr)
filtr_tg <- filter(ToothGrowth,dose==0.5)

Great! it worked. Thank you :slight_smile:
Why do I have to put library(dplyr) first before filtr_tg <- filter(ToothGrowth,dose==0.5) ?

The stats package in base R, which is loaded by default, has a different filter function. When you load the dplyr package, the filter from the stats package is masked and R will use dplyr's filter instead.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

Created on 2022-09-24 with reprex v2.0.2

1 Like

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.