![]() |
VOOZH | about |
R keywords are reserved words that have special meaning in the language. They help control program flow, define functions, and represent special values. We can check for which words are keywords by using the help(reserved) or ?reserved function.
Output:
Here are some important R keywords and their brief explanations:
if is used for decision-making to execute code only if a condition is true.
Output:
[1] "Positive Number"
else executes code when the if condition is false.
Output:
[1] "10 or less"
while is a loop which runs a block repeatedly while a condition remains true.
Output:
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
repeat runs a block indefinitely until explicitly stopped with break.
Output:
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
for loop iterates over a sequence, running code for each element.
Output:
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
function defines reusable blocks of code.
Output:
[1] "even"
[1] "odd"
next skips the current iteration in a loop and continues with the next.
Output:
[1] 6
[1] 7
[1] 9
[1] 10
[1] 11
break stops the execution of a loop immediately.
Output:
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
Boolean constants representing logical true and false values.
Output:
[1] TRUE
[1] FALSE
Represents an empty or undefined object.
Output:
NULL
Inf and -Inf represent positive and negative infinity. NaN means “Not a Number” and occurs in undefined numerical operations.
Output:
[1] FALSE TRUE TRUE
[1] FALSE TRUE FALSE
Represents missing or unavailable data.
Output:
[1] FALSE TRUE FALSE FALSE