Basic data types in R
R works with numerous data types. Some of the most basic types to get started are:
- Decimal values like
4.5
are called numerics. - Whole numbers like
4
are called integers. Integers are also numerics. - Boolean values (
TRUE
orFALSE
) are called logical. - Text (or string) values are called characters.
Note how the quotation marks in the editor indicate that "some text"
is a string.
This is a part of the course
“Introduction to R”
Exercise instructions
Change the value of the:
my_numeric
variable to42
.my_character
variable to"universe"
. Note that the quotation marks indicate that"universe"
is a character.my_logical
variable toFALSE
.
Note that R is case sensitive!
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Change my_numeric to be 42
my_numeric <- 42.5
# Change my_character to be "universe"
my_character <- "some text"
# Change my_logical to be FALSE
my_logical <- TRUE
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.