FAQ: Aggregates in R - Calculating Column Statistics

This community-built FAQ covers the “Calculating Column Statistics” exercise from the lesson “Aggregates in R”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn R

FAQs on the exercise Calculating Column Statistics

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

What is the point of the intermediary variable used within the summarize function, such as:

summarize(var_name=command(column))

We have to use another variable name at the beginning:

max_val ← df %>%
summarize(max_col = max(col))

I don’t see why we need both, or how they differ.

3 Likes

I don’t understand why all of the examples in the prompt begin with the select() function, as that indicates you need to specify which column you are operating on. I guess you don’t have to do that, as the actual example in the instructions doesn’t require that step. So I guess it’s unnecessary?

I don’t see why we need the summarize function at all here. I am getting valid output with:
most_expensive <- max(orders$price, na.rm = TRUE)

However I’m getting a failure from codecademy’s grading system.

I have the same question as jniager3. Does anyone have an update on this?

Why does the variable need to be defined in the max function when the variable must be defined in the beginning?

What is the purpose of the summarize function if it could be ignored using melecityjones method?

1 Like

You may be getting a failure from the grading system since it’s scoring based on your input and not your output. While you use a different syntax, you are still “piping” orders. What is the column name you get when you don’t use the recommended syntax?

1 Like

I was confused by this assignment too. But after completing the assignment that comes after this one, it all makes sense to me now.

They simply want to demonstrate the syntax for aggregating in R.
We’re basically creating a new DF under a new variable name with new columns that is the aggregated data, while dropping the original columns. It is kind of similar to transmute().

# assigning new DF name:
most_expensive <- orders %>%

# The following line is unnecessary, but it follows the same syntax when we start using groupby() in the next assignment. Same logic as a default parameter :
  select(price) %>%

# summarize aggregates the data into one row, it doesn't make sense now but it will when you apply groupby() on the next assignment.
  summarize(new_column_name = max(price, na.rm=TRUE))

most_expensive
3 Likes

image
Can anyone explain what this comment mean? what is “parsing” and which value in the df is missing?

image what does it mean?

Why is the function ‘summarize()’ needed in this exercise? Isn’t both the functions ‘max()’ and ‘n_distinct’ both return a single value?

most_expensive ← max(orders$price, na.rm = TRUE)

most_expensive

Why this isn’t good (Codecademy acceptable) solution for exercise 3?
Returns 493 into variable