Explore the 1985 Cars Dataset #9

Hi,

I’m working on the 1985 Cars Dataset and I’m stuck on #9https://www.codecademy.com/courses/learn-r/projects/1985-cars-r-project

My code:

Task 9


# filter rows

cars %>%

 filter(mpg_diff_from_threshold > 0)

Errors message:

# filter rows
cars %>%
 filter(mpg_diff_from_threshold > 0)

Error: Problem with `filter()` input `..1`.
ℹ Input `..1` is `mpg_diff_from_threshold > 0`.
✖ object 'mpg_diff_from_threshold' not found

Please halp!

This error is telling you that there’s no “mpg_diff_from_threshold” column. I guess that the problem is that you didn’t save the dataframe with the new created column to the variable “cars” when you created it in the Task 8.
The code ill be something like this:

# Task 8
# add column of highway_mpg
cars <- cars %>% # I guess this is the part that you missed. Save the new dataframe to the variable "cars"
  mutate(mpg_diff_from_threshold = highway_mpg - mpg_threshold) # Add the new column


# Task 9
# filter rows
new_variable <- cars %>%
  filter(mpg_diff_from_threshold > 0)

head(new_variable) #To inspect the new dataframe
4 Likes

Awesome, you’re a champion!

Does anybody have the answer for 10? I don’t understand what I did wrong.
cars %>%

filter(mpg_exceeds_threshold=) %>%

arrange(desc(mpg_diff_from_threshold))

cars ← cars %>%
arrange(mpg_exceeds_threshold = desc(mpg_diff_from_threshold))

I believe this is correct, or at least it’s not giving me an error code and it makes sense to me!

Please Help! I’m having trouble with Task 4 and Task 6.

Task 4

# select columns

cars <- cars %>%

select(-normalized_losses)


Error: Can't subset columns that don't exist.
✖ Column `normalized_losses` doesn't exist.

# Task 6
```{r error=TRUE}
# rename column

cars <- cars %>%
 rename(risk_factor = symboling)
  colnames(cars)

It keeps saying error every time I Save it

I have the same issue
I tried all the solution from the comments and it still not right…