AnatomyOf

Anatomy of an R file

example.r
1# A minimal R script. No semicolons were harmed in the making of this file.
2
3library(stats) # Load a package (this one ships with base R)
4
5nums <- c(4, 8, 15, 16, 23, 42)
6
7describe <- function(x) {
8 if (mean(x) > 10) {
9 cat("Above average, whatever \"average\" means.\n")
10 } else {
11 cat("Below average.\n")
12 }
13}
14
15for (n in nums) {
16 cat("Value:", n, "\n")
17}
18
19describe(nums) # Function call
R is a language and environment for statistical computing and graphics, widely used among statisticians and data miners for data analysis.