Code · 1 file

Sample R File

R is a language for statistics and data visualization. The R sample is a small program — a customer record, a VIP check and a formatted total — that is the same in every language we offer, so you can compare them side by side.

R · 417 B

Sample R file

An idiomatic R example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.

CC0 · free for any use · Verified by an independent tool · Report a problem

sample.R — first linesR
# Sample R script — samplefiles.com
customers <- data.frame(
  id = 1:3,
  name = c("Ada", "Grace", "Linus"),
  balance = c(12500, 830.5, 10000)
)
customers$vip <- customers$balance >= 10000

for (i in seq_len(nrow(customers))) {
  c <- customers[i, ]
  cat(sprintf("%-6s %10.2f %s\n", c$name, c$balance, if (c$vip) "VIP" else ""))
}
cat(sprintf("Total: %.2f\n", sum(customers$balance)))
summary(customers$balance)

File details

Size
417 B (417 bytes)
MIME type
text/x-r
SHA-256
ded79efdab213cb258bd688e4f8d603c8cf356640f67841bfaab63edacefacf0
MD5
f2ff927530620a49cacab517eb9d1adb

Download from the command line

curl -L -o sample.R https://files.samplefiles.com/code/r/sample.R

Or check the download in your browser with the checksum calculator.