R quick reference

Runs in Zerethon IDE · R 4.5 Official R documentation ↗

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, NA and NULL, class(), and converting with as.numeric() and friends.

  • Vectors

    Create vectors with c(), : and seq(), calculate on a whole vector at once, and pick elements by position or condition.

  • Conditions and loops

    if / else, vectorized ifelse(), switch(), for over a vector, while, and next / break.

  • Functions and apply

    Define functions with function, default arguments, return a list, and apply a function to every element with sapply and lapply.

Data

  • Lists and data frames

    Named lists, data frames (tables), selecting rows and columns, sorting with order(), adding columns and aggregate().

  • Strings

    paste and sprintf, nchar, substr, toupper, strsplit, and regular expressions with grepl, sub, gsub and regmatches.

  • Summary statistics

    mean, median, sd, quantile, table() for counts, correlation, summary(), and reproducible random numbers with set.seed().

Input and files

  • Reading input (stdin)

    Read what you type in the IDE's Input tab with readLines(file("stdin")) or scan().

  • Reading and writing files

    Read project files with read.csv and readLines, and write results under /tmp with write.csv and writeLines.

  • 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 bounds and missing value where TRUE/FALSE needed mean 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.

References