FAQ: Introduction to R Syntax - Calculations

This community-built FAQ covers the “Calculations” exercise from the lesson “Introduction to R Syntax”.

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

Learn R

FAQs on the exercise Calculations

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!

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

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

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!

Hi,

In the introduction to R Syntax under “Calculations” I believe there is an error (unless I’m missing something). The error

Results in “500”

573 - 74 + 1

^ in the above, if we’re working with good old order of operations of “PEMDAS” addition should happen prior to subtraction. So it would be 74+1=75 and then 573-75=498

Or have I missed something?

I know this is a small detail but I became obssesed with it and I’m grateful for your thoughts…

1 Like

Hello, I entered the following “25 * 4 + 9 / 3” under the notebook.Rmd but when I pressed “Run” I did not get a numeric result. Instead I got a message that says “Did you calculate the equation inside your R notebook?”…I thought notebook.Rmd was the R notebook…am I missing something?

Thank you!

4 Likes

Hello, @pyace87095.

Sorry, for replying so late, but I just noticed your post.

You’ve ignored the sign. 74 is a negative number. If you want to do the addition first, you have to add 1 to -74. That gives you -73. 573 - 73 = 500. Addition and subtraction is essentially a sum of a list of values. You have 3 values here: 573, -74, 1.

1 Like

Hello, @ashleybarnes00527705, and welcome to the forums.

Sounds like you may have not entered your code in the correct space, or if you included the quotation marks like you show in your post, that would be an issue as well.
image

Your code should go where I’ve indicated in the screenshot.
Happy coding!

1 Like

Apparently (and I’m guessing here), the spaces between the numbers and mathematical signs are important… I had the same issue you had, with same response of “did you calculate…”, and finally had to have code academy “solve for me”. The only difference I could find between what I entered and what code academy displayed were spaces between each value [ 25 * 4 + 9 / 3 ]… if this is what caused the issue, I would think, given that this course is for people with zero experience or background in coding and R, that it would be paramount to communicate the need to use a space… Hoping it only gets better from here.

1 Like

Hi -
Completely new to codecademy and r. The first exercise we are asked to perform a simple calculation 25 * 4 + 9 / 3. Below is the solution:

title: “Introduction to R Syntax”
output: html_notebook

25 * 4 + 9 / 3

My question is why does {r} need to be included? and what function does the ``` perform?

Thank you

Hi array4025038106,

Codecademy uses something called R Markdown to embed R code. It is basically a way to include commentary and explanations in the same place with your code, and all graphics that it produces. Researchers use it to make their analysis reproducible by other people, and for many other things!

The syntax '''{r} tells R Markdown that it should expect some R code to follow, and another ''' closes the code block. If you’re interested, here’s some info on code chunks from the manual:

I hope this helps, and all the best,

1 Like

Hello, I entered the following “25 * 4 + 9 / 3” under the notebook.Rmd but when I pressed “Run” I did not get a numeric result. Instead I got a message that says “Did you calculate the equation inside your R notebook?”…I thought notebook.Rmd was the R notebook…am I missing something?

This has been raised by few others - could you give me a step by step way how to solve it as I’m new to this and it’s quite frustrating - thank you.

1 Like

The result should be 108.3 but I displays 103. Why?

Not sure how you’re getting 108.3

25*4+9/3
100+9/3
100+3
103

2 Likes

this is comment was most helpful, I thought I was going mad.

1 Like

Thank you! Does anyone know why it has to go here? Is there significance to those apostrophe marks?

1 Like

I’ve got little to no experience using R. I’ve only dabbled in the Codecademy course. I found this link which you may find helpful. The short answer to your question though, is yes. The back ticks followed by {r} are are significant. The link explains using R with an html notebook.

I’m having the same problem:

Hello, I entered the following “25 * 4 + 9 / 3” under the notebook.Rmd but when I pressed “Run” I did not get a numeric result. Instead I got a message that says “Did you calculate the equation inside your R notebook?”…I thought notebook.Rmd was the R notebook…am I missing something?

Thank you!

Hi, hoping to get some help–I’m not sure I understand why the colors differ between example and notebook.Rmd? Does it matter? Thanks!

Follow DMAS rule divide, multiply, add and subtract

25(M)4(A)9(D)3

254+9/3
25
4+3
100+3
103

Hi there, I also get the Error simlar to saying “Did you enter your code in the Notebook.RND area” and I enetered the code with correct spaces 25 * 4 - 9 / 3
I am a blind text to speech user, using Microsoft Edge and the Jaws screen reader. Jaws announces Notebook.rnd active and gives me an edit box saying “Code Edit Area” where I enter this code, but everytime I press on the Run Code button I get that error, and also thus can’t move onto the next page/step. Is there any space in that edit area I need to move to, they talk about an R block to enter the code, but as I said Jaws only gives me a normal edit box like all web sites with text entry boxes do. Any advise would be highly appreciated.

I ran this same equation in Rstudio and the spaces didn’t matter, whereas without the spaces it would not run on the “notebook.Rmd” version. I have no idea what going on there, but I agree there no way you can skip vital directions like including spaces or not. Its like a password, Is it case sensitive? There is a 100% difference there (if it is case sensitive)

I hope this helps. Had to have my husband help me since I was going crazy. I tried indicating it nicely in this half hand-drawn image. :slight_smile:

2 Likes