R quick reference
R 4.5 essentials: vectors and types, control flow, functions, lists and data frames, strings, summary statistics, input and files — and how an R script runs in Zerethon IDE.
Written for R 4.5. Examples that show an output were run in the Zerethon sandbox (R 4.5) on 2026-10-24.
Basics
-
Hello, World
The smallest R script, and the difference between
print(),cat()and a value on its own line. -
Variables and types
Numbers, integers, text, logicals,
NAandNULL,class(), and converting withas.numeric()and friends. -
Vectors
Create vectors with
c(),:andseq(), calculate on a whole vector at once, and pick elements by position or condition. -
Conditions and loops
if/else, vectorizedifelse(),switch(),forover a vector,while, andnext/break. -
Functions and apply
Define functions with
function, default arguments, return a list, and apply a function to every element withsapplyandlapply.
Data
-
Lists and data frames
Named lists, data frames (tables), selecting rows and columns, sorting with
order(), adding columns andaggregate(). -
Strings
pasteandsprintf,nchar,substr,toupper,strsplit, and regular expressions withgrepl,sub,gsubandregmatches. -
Summary statistics
mean,median,sd,quantile,table()for counts, correlation,summary(), and reproducible random numbers withset.seed().
Input and files
-
Reading input (stdin)
Read what you type in the IDE's Input tab with
readLines(file("stdin"))orscan(). -
Reading and writing files
Read project files with
read.csvandreadLines, and write results under/tmpwithwrite.csvandwriteLines. -
Several files and packages
Load your own functions from another file with
source(), and which packages are available without installing.
In Zerethon IDE
-
Running R in Zerethon IDE
What Run does with your script, the time limit, input, tests, and what a run cannot do.
-
Common errors
What
object not found,could not find function,non-numeric argument,subscript out of boundsandmissing value where TRUE/FALSE neededmean and how to fix them. -
Official documentation
Where to read more: An Introduction to R, the R language definition, and the help pages of every function.