Variables

📦 Ready to store some data? In R, variables help you store and label information so you can reuse it later. Let’s walk through how to create, update, and inspect variables.

Assignment

Use <- or = to assign a value to a variable.

Naming

  • Must start with a letter or .
  • Cannot start with a number
  • Can only contain letters, numbers, . or _
  • Are case-sensitive

Reassignment

You can update a variable’s value anytime.

Multiple Assignment

Assign the same value to multiple variables.

Dynamic Typing

R is dynamically typed — variables can change type based on what’s assigned.

Best Practices

  • Use clear, meaningful names (e.g., total_score > ts)
  • Stick to snake_case for readability
  • Don’t name variables after built-in functions (c, mean, etc.)
  • Use typeof() and class() to check what kind of data you’re working with