Learning R Variables

Understanding how to declare and use variables in R

Declaration and Assignment

In R, you can declare variables using the assignment operator (<-) or with the = sign.

x <- 10
y = "hello"
z <- TRUE

Naming Conventions

Variable names in R are case-sensitive and can contain letters, numbers, periods, and underscores. They cannot start with a number or contain spaces.

myVariable <- 20
another.variable <- "world"
third_variable <- FALSE

Practice Exercises

Now that you've learned about variables in R, it's time to practice. Try the following exercises to test your understanding:

  1. Declare a variable age and assign your age to it.
  2. Create a variable name and assign your name to it.
  3. Declare a logical variable isStudent and assign TRUE if you are a student, or FALSE otherwise.