R Variables

  • Variables are containers for storing data values
  • We use the <- sign to assign variables

Variable Name Rules in R

  • variable names can consist of letters, numbers, dots, and underscores.
  • They must start with a letter or a dot followed by a letter.
  • Variable names are case sensitive: “myVar” and “myvar” are considered different variables.
  • Avoid using reserved keywords as variable names, as they have special meanings in R. Example, print, paste, function, etc
  • Choose a consistent naming convention for variables. Common conventions include camel case and underscore separation.
  • Choose descriptive variable names

Example of a variable

From the above, first_name is considered the variable and ‘John’ the value. Therefore the above has 2 variables and 2 values

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top