How it works
In the editor, you should type R code to solve the exercises. When you submit your code, every line of code is interpreted and executed by R and you get a message whether or not your code was correct. The output of your R code is shown in the console.
R makes use of the #
sign to add comments, so that you and others can understand what the R code is about. Just like Twitter! Comments are not run as R code, so they will not influence your result. For example, Calculate 3 + 4 in the editor is a comment.
You can also execute R commands straight in the console. This is a good way to experiment with R code, as your submission is not checked for correctness.
This is a part of the course
“Introduction to R”
Exercise instructions
- In the editor there is already some sample code. Can you see which lines are actual R code and which are comments?
- Add a line of code that calculates the sum of 6 and 12, and submit your code.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Calculate 3 + 4
3 + 4
# Calculate 6 + 12
This exercise is part of the course
Introduction to R
Master the basics of data analysis in R, including vectors, lists, and data frames, and practice R with real data sets.
Take your first steps with R. In this chapter, you will learn how to use the console as a calculator and how to assign variables. You will also get to know the basic data types in R. Let's get started.
Exercise 1: How it worksExercise 2: Arithmetic with RExercise 3: Variable assignmentExercise 4: Variable assignment (2)Exercise 5: Variable assignment (3)Exercise 6: Apples and orangesExercise 7: Basic data types in RExercise 8: What's that data type?What is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.