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 |
---|---|
if | Used to specify a block of code to execute if a condition is true. |
else | Specifies a block of code to execute if the condition in an if statement is false. |
repeat | Creates an infinite loop that can be terminated using the break statement. |
while | Creates a loop that continues to execute as long as a specified condition is true. |
for | Used to iterate over a sequence or vector. |
function | Defines a function, which is a block of code designed to perform a specific task. |
return | Returns a value from a function and exits the function. |
break | Terminates the execution of a loop prematurely. |
next | Skips the current iteration of a loop and continues with the next iteration. |
TRUE | A logical constant representing the boolean value true. |
FALSE | A logical constant representing the boolean value false. |
NA | Represents a missing or undefined value in R. |
NULL | Represents the absence of a value or an empty object. |
Inf | Represents infinity, which can be the result of division by zero. |
NaN | Stands for 'Not a Number' and is used to represent undefined numerical results. |
... | Used to represent a variable number of arguments in a function. |
break | Exits a loop before it has finished all iterations. |
next | Skips 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.