All Tech Guides

Tech Guide

Install R and Run Your First Analysis

An introduction to the R language for statistics and data analysis, how to install R on Windows, macOS, and Linux, and a beginner example in the R console.

Programming Beginner Updated October 2026

Disclaimer & Important Cautions

These Tech Guides and instructions are provided in good faith as a general educational guide. Technology changes over time, and settings, software versions, installation steps, and security practices may vary by system.

I cannot guarantee that these steps will work in every environment, and I am not responsible for data loss, configuration problems, system errors, security issues, downtime, or other problems that may result from following this guide.

  • Download R only from CRAN, the official R distribution site, or your Linux package manager.
  • Use administrator privileges carefully when installing software.
  • Install add-on packages only from trusted sources such as CRAN.
  • Do not share data files that contain private or confidential information.
  • When in doubt, consult official documentation or a qualified technician.

Overview

R is a free, open-source programming language and environment built for statistics, data analysis, and data visualization. It was created in the early 1990s by Ross Ihaka and Robert Gentleman at the University of Auckland and is maintained by the R Core Team. R is widely used in research, data science, finance, health sciences, and business analytics.

Much of R's power comes from packages: over 20,000 free add-ons on CRAN (the Comprehensive R Archive Network) for everything from data cleaning to machine learning and publication-quality graphics. The current version is R 4.6, released in April 2026.

Main idea: Install R first. Most people then write R code in RStudio, an editor that runs on top of R, but R also works on its own, as this guide shows.

Requirements

  • A Windows, macOS, or Linux computer.
  • Administrator privileges to install software.
  • Internet access.

Important Notes

  • R and RStudio are separate programs. Install R first, then RStudio (see the RStudio guide).
  • R is case-sensitive: mean() works, but Mean() does not.
  • A new version of R is released each spring. Packages you installed may need reinstalling after a major upgrade.

R Installation Instructions

Choose the tab for your operating system:

Installing R

Click the tab above for your operating system.

The guide covers these major tasks:

  1. Download R from CRAN.
  2. Run the installer.
  3. Open R.
  4. Confirm the version.

Confirm the installation

When R opens, it shows a startup message with the version number, followed by the > prompt where you type commands. You can also check the version by typing:

R.version.string

R responds with something like:

[1] "R version 4.6.1 (2026-06-24)"
Check yourself: R opens to a > prompt and reports version 4.6 or later.

Beginner Example: Exploring Data in the R Console

Type each block at the > prompt and press Enter. Lines starting with # are comments; you can skip them. The [1] at the start of output simply means "first value."

Step 1: R as a calculator and variables

2 + 3 * 4
sqrt(144)

# Store a value in a variable with <-
hours <- 40
rate <- 18.50
hours * rate

Output:

[1] 14
[1] 12
[1] 740

Step 2: Vectors and statistics

A vector is a list of values, created with c(). Most R functions work on a whole vector at once:

scores <- c(78, 85, 92, 67, 88, 95, 73)

mean(scores)
median(scores)
max(scores)
sd(scores)        # standard deviation
scores[scores >= 85]   # only scores of 85 or higher

Output:

[1] 82.57143
[1] 85
[1] 95
[1] 10.27711
[1] 85 92 88 95

Step 3: Data frames

A data frame is R's version of a table or spreadsheet. R includes sample data sets; mtcars has data on 32 car models:

head(mtcars)            # first six rows
nrow(mtcars)            # number of rows
summary(mtcars$mpg)     # summary of the miles-per-gallon column
mean(mtcars$mpg[mtcars$cyl == 4])   # average mpg for 4-cylinder cars

The $ picks a column by name. The last line returns about 26.66 miles per gallon.

Step 4: A chart

R draws charts with one line of code. This opens a scatter plot in a new window:

plot(mtcars$wt, mtcars$mpg,
     main = "Car Weight vs. Fuel Economy",
     xlab = "Weight (1000 lbs)",
     ylab = "Miles per Gallon",
     pch = 19, col = "steelblue")

The plot shows that heavier cars tend to get fewer miles per gallon.

Step 5: Write a function and install a package

# A function that converts Fahrenheit to Celsius
to_celsius <- function(f) {
  (f - 32) * 5 / 9
}
to_celsius(c(32, 72, 212))

# Install a package from CRAN (only needed once), then load it
install.packages("praise")
library(praise)
praise()

The function returns 0.00000 22.22222 100.00000. When you install a package for the first time, R may ask you to choose a CRAN mirror (download site); choose 0-Cloud or one near you. praise() prints a random compliment, confirming the package works.

Check yourself: mean(scores) returns 82.57143, the scatter plot opens, and praise() prints a message.

Useful Tips

  • Type ?mean (or ? followed by any function name) to open its help page.
  • Press the Up arrow to bring back previous commands.
  • If you see a + prompt instead of >, R is waiting for you to finish a command (often a missing closing parenthesis). Press Esc to cancel.
  • To quit R, type q(). Answer n when asked whether to save the workspace.

Next Steps

  • Install RStudio for a much more comfortable place to write R code.
  • Explore the tidyverse packages (install.packages("tidyverse")) for data cleaning and ggplot2 charts.
  • Read R for Data Science, a free online book.
Final Notes:
  • R is a free language for statistics, data analysis, and graphics.
  • Download R from CRAN, and install it before RStudio.
  • Vectors and data frames are the core ways R stores data.
  • Install packages once with install.packages(), and load them each session with library().
Explore more technology resources

Return to the complete collection of installation and configuration guides.

Browse All Tech Guides