Introduction to R
R is a dynamically typed, interpreted language built for statistics and data analysis — not general-purpose programming first with stats bolted on, but the other way around. It has no compile step: an R script runs top to bottom the moment you execute it, the same as Python or Ruby.
Its single most distinctive feature is this: R has no true scalars. In most languages on this site, 5 is one value and [5, 6, 7] is a different kind of thing — a collection. In R, 5 is already a numeric vector, just one with length 1. There is no special "lone number" type sitting apart from "a sequence of numbers" — everything is a vector, and a plain value is simply a vector you haven't bothered to make longer yet. This single fact is why R's arithmetic, indexing, and even its error messages all look the way they do, and this course treats it as the organizing idea behind nearly every lesson that follows.
A quick preview
Here's a real R program, executed for real on this page's own compiler — not a mockup. nums * 2 and sum(nums) both operate on the whole vector at once, with no loop written anywhere.
nums <- c(1, 2, 3, 4, 5)
cat("R in action:\n")
print(nums * 2)
cat("Sum:", sum(nums), "\n")
R in action: [1] 2 4 6 8 10 Sum: 15
c(1, 2, 3, 4, 5) builds a vector of five numbers, and nums * 2 multiplies every one of them by 2 in a single expression — the kind of operation that would need an explicit loop (or a map call) in most other languages on this site. sum(nums) reduces the whole vector to one number, which, as you now know, is really just a vector of length 1. Next: your first program — print, cat, and comments, with no compile step and no main function required.
Practice exercise
Create a vector called nums containing 2, 4, and 6 using c(), then print nums * 10 to see the whole vector multiplied at once, with no loop.