1. Variables & Basic Types

Learn R variable assignment and basic types (numeric, character, logical) with live, editable R code.

In R, you create a variable with the assignment arrow <- (an equals sign = also works). R has a few core types: numeric, character (text), and logical (TRUE/FALSE). Use class() to check a value’s type.

Discuss first

Before you run the code below: is_student is assigned TRUE. What do you think class(is_student) would print? Is TRUE the same kind of value as 25 or as "Ada"?

Edit the code below if you like, then press Run Code to check your answer.

Check your understanding

Q1. Which operator is the idiomatic way to assign a value to a variable in R?

Q2. Fill in the blank: given age <- 25, the call below prints "numeric".

____(age)
Back to top