Menu
Coddy logo textTech

Numeric Data Type

Part of the Fundamentals section of Coddy's R journey — lesson 4 of 78.

Variables are like containers that hold data. Instead of typing the same number or value repeatedly, you can store it in a variable and use it whenever needed. In R, you create variables using the assignment operator <-, which is the standard way to assign values.

The basic syntax for creating a variable is:

variable_name <- value

For example, to store the number 42 in a variable called age, you would write:

age <- 42

Once you create a variable, R remembers its value, and you can use the variable name anywhere you would use the actual value. This makes your code more readable and easier to modify later.

Variables have different types. The numeric data type is used to store any number, whether it's a whole number like 42 or a decimal number like 3.14.

challenge icon

Challenge

Easy

Create a variable called temperature and assign it the value 25. Then create another variable called quantity and assign it the value 13. Finally, display both variables using the print() function.

Cheat sheet

Variables store data and are created using the assignment operator <-:

variable_name <- value

Example with numeric values:

age <- 42
pi_value <- 3.14

To display a variable's value, use print():

print(age)

Try it yourself

# TODO: Write the variables below


# Don't delete the rows below
print(temperature)
print(quantity)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals