R Keywords

Keywords in R are reserved words that have predefined meanings and are used to structure R code. These keywords cannot be used as identifiers (like variable names) in your programs. Understanding these keywords is essential for writing effective R scripts.

Key Topics

1. List of R Keywords

Below is a comprehensive list of R keywords and their descriptions:

Keyword Description
ifUsed to specify a block of code to execute if a condition is true.
elseSpecifies a block of code to execute if the condition in an if statement is false.
repeatCreates an infinite loop that can be terminated using the break statement.
whileCreates a loop that continues to execute as long as a specified condition is true.
forUsed to iterate over a sequence or vector.
functionDefines a function, which is a block of code designed to perform a specific task.
returnReturns a value from a function and exits the function.
breakTerminates the execution of a loop prematurely.
nextSkips the current iteration of a loop and continues with the next iteration.
TRUEA logical constant representing the boolean value true.
FALSEA logical constant representing the boolean value false.
NARepresents a missing or undefined value in R.
NULLRepresents the absence of a value or an empty object.
InfRepresents infinity, which can be the result of division by zero.
NaNStands for 'Not a Number' and is used to represent undefined numerical results.
...Used to represent a variable number of arguments in a function.
breakExits a loop before it has finished all iterations.
nextSkips the current iteration of a loop and proceeds to the next iteration.

Key Takeaways

  • R keywords are reserved and have specific meanings in the language.
  • You cannot use these keywords as variable or function names.
  • Understanding the purpose of each keyword is important for writing efficient R code.