Name: R
Creator(s): Ross Ihaka and Robert Gentleman
Date: August 1993
Website: The R Project
R is a programming language and free software environment for statistical computing and graphics. It is supported by the R Core Team and the R Foundation for Statistical Computing. It is widely used among statisticians and data miners for developing statistical software and data analysis. It is written primarily in C, Fortran and R itself (partially self-hosting) and is available under the GNU General Public License.
To run an R script from the terminal use the command Rscript file.r
.
Variables in R can be assigned using a leftward (<-
), rightward (->
) and equal (=
) to operator.
greeting = "Hello World!"
number <- 42
FALSE -> bool
print(greeting)
print(number)
print(bool)
If/Else statements in R are like many other languages with brackets around the condition and curly braces around the body.
if (TRUE) {
print("True!")
} else {
print("False!")
}
The most common loops in R are for loops and while loops. The syntax is very much the same as other languages with brackets around the condition and curly braces around the body.
Here is an example for loop:
letters = c("A", "B", "C")
for (letter in letters) {
print(letter)
}
Here is an example while loop:
num = 0
while (num < 10) {
print(num)
num = num + 1
}
Functions in R are also very much the same as other languages with brackets around the condition and curly braces around the body.
add <- function(num1, num2=42) {
return(num1 + num2)
}
print(add(1, 2))
print(add(3))