List of keywords in R programing language

Keywords in the R programming language are reserved words that have special meanings and cannot be used as variable names or function names. Here is a list of keywords in R:

  • if
  • else
  • repeat
  • while
  • function
  • for
  • in
  • next
  • break
  • TRUE
  • FALSE
  • NULL
  • Inf
  • NaN
  • NA
  • NA_integer_
  • NA_real_
  • NA_complex_
  • NA_character_

Here are a few examples of how some of the keywords in R are used:

if and else:

x <- 10

if (x > 5) {

  print(“x is greater than 5”)

} else {

  print(“x is not greater than 5”)

}

repeat and break:

i <- 1

repeat {

  print(i)

  i <- i + 1

  if (i > 5) {

    break

  }

}

While:

i <- 1

while (i <= 5) {

  print(i)

  i <- i + 1

}

For:

for (i in 1:5) {

  print(i)

}

Function:

square <- function(x) {

  return(x^2)

}

result <- square(4)

print(result)

in (used in for loops):

fruits <- c(“apple”, “banana”, “cherry”)

for (fruit in fruits) {

  print(fruit)

}

TRUE and FALSE:

is_raining <- TRUE

is_sunny <- FALSE

NULL:

empty_vector <- NULL

NA:

missing_value <- NA

These are just some basic examples of how keywords are used in R. Depending on the context and your specific programming needs, you may encounter and use these keywords differently.

You can always refer to the official R documentation or the help system within R itself for the most up-to-date information on keywords and their usage.

Leave a Comment

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