'Object not found' in 'ToothGrowth' dataset

I am taking the Google Data Analytics course, and I'm trying to reproduce the instructor's code. I typed exactly what she has:

data("ToothGrowth")
View(ToothGrowth)
filtered_tg <- filter(ToothGrowth, dose==0.5)

But when I run the code in R Desktop, I get "Error in filter(ToothGrowth, dose == 0.5) : object 'dose' not found". I can't for the life of me figure out what is wrong. This works in R Cloud, btw, just not in the Desktop version. Any help would be greatly appreciated; I'm about to throw it all out the window and play MMORPG games so I can kill things in a socially acceptable manner...

Try executing

library(dplyr)

before you use the filter function. I think your code is using the filter function from base R instead of the function from the dplyr package.

I made sure dplyr was installed and loaded; I did it again as per your advice, and it didn't make a difference.

The code works for me when I include a call to library(dplyr). Does the code below not work for you?

library(dplyr)

data("ToothGrowth")
View(ToothGrowth)

filtered_tg <- filter(ToothGrowth, dose==0.5)
head(filtered_tg)
#>    len supp dose
#> 1  4.2   VC  0.5
#> 2 11.5   VC  0.5
#> 3  7.3   VC  0.5
#> 4  5.8   VC  0.5
#> 5  6.4   VC  0.5
#> 6 10.0   VC  0.5

Created on 2023-02-01 with reprex v2.0.2

I did exactly the same thing and I still get the same result:

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

data("ToothGrowth")

View(ToothGrowth)

filtered_tg <- filter(ToothGrowth, dose==0.5)

Created on 2023-02-01 with reprex v2.0.2

Why would it work in R Cloud but not on my desktop when it worked before?

I don't have any good suggestions. Have your tried restarting R?

Restarting the computer the next day didn't change anything.

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