Understanding the fundamentals of R programming
In R, you can create variables to store data. R has several built-in data types, including numeric, character, logical, and more.
const > x <- 10
const > y <- "hello"
const > z <- TRUE
You can use conditional statements like if-else to make decisions in R based on certain conditions.
const > x <- 10
const > if (x > 5) print("greater than 5") else
print("less than or equal to 5")
You can use loops like for and while to repeat a block of code multiple times.
const > for (i in 1:5) print(i)
You can define your own functions in R to encapsulate a block of code for reuse.
const > square <- function(x) return(x^2)
const > print(square(3))
Now that you've learned the basics of R syntax, it's time to practice. Try the following exercises to test your understanding: