Help with Data Frames in R Project (Explore The 1985 Cars Dataset)

I’m currently attempting the project for the Data Frames lesson in R. The directions are making sense to me, and I felt I was coding correctly and can’t find my error.

For Task 4, I got this error message: " ```
Error in select(-normalized_losses): object ‘normalized_losses’ not found

For Task 6, i got this error message: " ```
Error in rename(risk_factor = symboling): object 'symboling' not found

For Task 8, I got this error message: " ```
Error in mutate(mpg_diff_from_threshold = highway_mpg - mpg_threshold): object ‘highway_mpg’ not found

I am extremely new to coding! I have attached my code below, and here is a link to the project page: [https://www.codecademy.com/courses/learn-r/projects/1985-cars-r-project]

I am sure I am just making a simple mistake, but I’m so stuck!

---
title: "1985 Cars"
output: html-notebook
---

# Task 1
```{r message=FALSE, warning=FALSE, error=TRUE}
# load libraries
library(readr)
library(dplyr)

Task 2

# load data
cars <- read_csv('cars85.csv')

Task 3

# inspect data
head(cars)
summary(cars)

Task 4

# select columns
cars %>% 
 cars <- select(-normalized_losses) 


Task 5

# view columns
colnames(cars)

Task 6

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


Task 7

# define threshold
  mpg_threshold <- 30

Task 8

# add column
cars %>%
  cars <- mutate(mpg_diff_from_threshold = highway_mpg - mpg_threshold)
  head(cars)



(My information might not be super specific since I am a beginner. I will try my best.) For task 4 and 6, it doesn’t work since you need to take the values from “cars %>%”. You need to be specific and indicate that you take data from your “cars” file as well as informations from “cars” data frame. So you need to add an arrow before “cars %>%”: cars ← cars %>%

1 Like

Ah, thank you! I thought I was doing that, but I had the order mixed up as to how to achieve it!
My correct code ended with:

Task 4

# select columns
cars <- cars %>% 
  select(-normalized_losses) 

and

# Task 6
```{r error=TRUE}
# rename column
cars <- cars %>%
 rename(risk_factor = symboling)
  colnames(cars)


Thank you :)

Hi chip :), wanted to ask what your code is for task 8? I keep getting this error message:

Error in UseMethod(“mutate”): no applicable method for ‘mutate’ applied to an object of class “character”

cars %>%
  mutate(mpg_diff_from_threshold = highway_mpg - mpg_threshold)

step 9 please,

I wrote the code several times but it does not work.
could any one please share the right code for step 9

this worked for me:
mpg_exceeds_threshold<-cars%>%filter(mpg_diff_from_threshold > 0)

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
1 Like

Yes, I have the same problem with Task 4!

I have a problem create a right code of task 9

mpg_exceeds_threshold ← cars %>%
filter(mpg_diff_from_threshold >0)

It shows an error of “mpg_diff_from_threshold” is not found

Need Help! Thank you!

Can you share a screenshot which shows all the code you have written for tasks 1 through 9?

Perhaps it may reveal clues as to whether you have completed the prior steps correctly or not.

There is an upload button in the forum post editor.

You can also copy and paste your code in the forums provided you format it correctly. At the bottom of the exercise/project, there should be a “Copy to Clipboard” button. To paste the code with correct formatting, see this thread: [How to] Format code in posts