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 <- valueFor example, to store the number 42 in a variable called age, you would write:
age <- 42Once 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
EasyCreate 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 <- valueExample with numeric values:
age <- 42
pi_value <- 3.14To 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)This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 2
Logical Operators (AND, OR)Logical Operators Part 2 (NOT)Recap - Simple LogicVectorized Logic Part 1Vectorized Logic Part 22Variables and Data Types
Numeric Data TypeInteger Data TypeCharacter Data TypeLogical Data TypeChecking Data TypesNaming ConventionsMissing Values: NARecap - Variable Creation8Loops
For LoopWhile LoopBreakNext (Continue)Recap - FactorialSequence Generation (seq, :)Nested LoopsRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsInteger Division and ModuloAssignment OperatorsRecap - Simple MathComparison Operators6Basic IO
Print OutputCat for OutputOutput With VariablesReading Input with readline()Type Conversion BasicsRecap - Age CalculatorRecap - True or False9Functions
Declaring a FunctionFunction ArgumentsReturn ValuesRecap - Sigma FunctionRecap - Validation FunctionDefault Parameter Values