Short answer: In R, everything is a vector: c(3, 1, 2) builds one, operations apply element by element, and indexes start at 1. Assign with <-, subset with x[x > 1] or df[df$cpu > 50, ], loop less and use sapply, vapply or Map instead, chain steps with the native pipe |>, and write short functions as \(x) x + 1. Read data with read.csv(), catch errors with tryCatch(), and summarise with summary(), table() and aggregate(). (Reviewed October 2026.)
The examples in this R cheat sheet were run with R 4.3.3 on 9 October 2026, using base R only. The current release is R 4.6.1; functions marked 4.4+ or later were checked against the R NEWS file.
as.POSIXct("09/Oct/2026:10:00:00", format = "%d/%b/%Y:%H:%M:%S", tz = "UTC")
Time difference
difftime(t2, t1, units = "mins")
Run a command
system2("uptime", stdout = TRUE)
For server admins:Rscript runs R non-interactively, so it fits in cron jobs and pipelines: Rscript report.R, or one-liners such as Rscript -e 'summary(read.csv("latency.csv")$ms)'. Install the interpreter from the distribution (dnf install R from EPEL on AlmaLinux, apt install r-base on Debian and Ubuntu).
In short: A compact reference for base R with tables for vectors, subsetting, data frames, functions, strings, files, error handling and quick statistics.R Cheat Sheet: what this guide covers.
Necessary cookies enable essential site features like secure log-ins and consent preference adjustments. They do not store personal data.
None
Functional cookies support features like content sharing on social media, collecting feedback, and enabling third-party tools.
None
Analytical cookies track visitor interactions, providing insights on metrics like visitor count, bounce rate, and traffic sources.
None
Advertisement cookies deliver personalized ads based on your previous visits and analyze the effectiveness of ad campaigns.
None
Unclassified cookies are cookies that we are in the process of classifying, together with the providers of individual cookies.
None
Try:
Free checklist
cPanel and DirectAdmin server hardening checklist
A two-page PDF of the checks we run on every hosting server: SSH, firewall, PHP, mail, backups and updates. Get it with the srvScripts newsletter (about twice a month, one-click unsubscribe).
We send a confirmation link first; the download appears after you confirm. Privacy policy.
srvScripts GenieFinds the right tool, guide or fix
Tell me what is wrong, for example emails going to spam, SSL expired on example.com or 550 5.7.1 rejected. Add a domain or IP address and I run a quick check right here, for example check DNS for example.com.
Never paste passwords or keys. Unanswered questions are kept for up to 90 days to improve our guides, with keys, passwords, IP and e-mail addresses masked (best effort: leave out confidential details), and without your IP address, account or cookies. Details