Get startedGet started for free

Variable assignment

A basic concept in (statistical) programming is called a variable.

A variable allows you to store a value (e.g. 4) or an object (e.g. a function description) in R. You can then later use this variable's name to easily access the value or the object that is stored within this variable.

You can assign a value 4 to a variable my_var with the command

my_var <- 4

This exercise is part of the course

Introduction to R

View Course

Exercise instructions

Over to you: complete the code in the editor such that it assigns the value 42 to the variable x in the editor. Submit the answer. Notice that when you ask R to print x, the value 42 appears.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Assign the value 42 to x
x <- 

# Print out the value of the variable x
x
Edit and Run Code