Manipulating Data Frames Explore 1985 Cars Dataset

Welcome to the Get Help category!

This is where you can ask questions about your code. Some important things to remember when posting in this category :slight_smile:

  • Learn how to ask a good question and get a good answer!
  • Remember to include a link to the exercise you need help with!
  • If someone answers your question, please mark their response as a solution :white_check_mark:
  • Once you understand a new concept, come back and try to help someone else!

Hi everyone! I am doing the exercise of the 1985 Cars Dataset (<https://www.codecademy.com/courses/learn-r/projects/1985-cars-r-project) and I am stuck in task 8 ( Add a new column to cars called mpg_diff_from_threshold . This will measure how far each car’s highway mpg is from 30 mpg. View the updated cars dataframe.)

This error comes up and I really don’t know what I am doing wrong, probably the most silly thing!

# add column
cars >%> 
    mutate(mpg_diff_from_threshold = highway_mpg - mpg_threshold)
Error: <text>:2:7: unexpected input
1: # add column
2: cars >%> 
         ^

Can someone help me? thanks!

Your pipe is the wrong way. The percent signs surround the greater than sign. %>%

Thanks! I realised just after posting, and also I missed the β€œ/30” at the end. It worked and I was able to finish the exercise.

Question 10 asks for " Which cars have the highest miles per gallon on the highways? To find this, arrange the rows of mpg_exceeds_threshold by mpg_diff_from_threshold descending. Save this new dataframe as mpg_exceeds_threshold "
I get the error ```
Error: Problem with filter() input ..1.
:information_source: Input ..1 is mpg_exceeds_threshold.
:heavy_multiplication_x: Input ..1$risk_factor must be a logical vector, not a double.


mpg_exceeds_threshold <- mpg_exceeds_threshold %>%

  filter(mpg_exceeds_threshold) %>%

  arrange(desc(mpg_diff_from_threshold))

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.