Integer Data Type
Part of the Fundamentals section of Coddy's R journey — lesson 5 of 78.
While the numeric data type handles all kinds of numbers, R also has a specific integer data type for whole numbers. Integers are numbers without decimal points, like 1, 42, or 100.
To create an integer variable in R, you need to append the letter L to your number. This tells R that you specifically want an integer rather than the default numeric type:
count <- 5L
age <- 25LThe key difference is that 5 creates a numeric variable, while 5L creates an integer variable. Both store the same value, but R treats them as different data types internally. This distinction becomes important in certain programming situations where you need precise control over your data types.
Cheat sheet
R has a specific integer data type for whole numbers. To create an integer, append the letter L to the number:
count <- 5L
age <- 25LWithout the L, R creates a numeric type by default. For example, 5 is numeric, while 5L is an integer.
Try it yourself
This lesson doesn't include a code challenge.
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