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()andclass()to check what kind of data you’re working with