Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 39 ยท Getting Started

What Is R?

Learn what R is, what it is used for, how it differs from Python and Excel, and how an R analysis flows from raw data to results you can share.

R is a programming language built for working with data. Statisticians created it in the 1990s, and it has grown into one of the main tools for data analysis, statistics, visualization and research. If you have ever wished a spreadsheet could repeat your steps automatically, draw publication-quality charts, or fit a statistical model in one line, R is designed for exactly that.

In this course you will go from your first calculation to cleaning data, drawing charts, running statistical tests and building models. This first lesson explains what R is, what people use it for, and how a typical R project is organized.

About the examples: R cannot run inside this website, so every R snippet in this course is read-only. Copy the code into your own R session (the next lesson shows how to install one) and run it there. Output is printed under the code only where it is simple and certain, so you can compare it with what you see.

What R is good at

R was designed around data first and general programming second. Three things make it stand out:

  • Vectors are the basic unit. A single number is just a vector of length one, and almost every operation works on whole collections at once. You write prices * 1.2 instead of looping over each price.
  • Statistics is built in. Means, medians, correlations, t-tests, linear and logistic regression, probability distributions and random sampling ship with the language.
  • A huge package ecosystem. Thousands of free packages (collections of ready-made functions) cover everything from machine learning to genetics to finance. You will use some of them in R Packages.

People use R for:

  • exploring and cleaning messy data;
  • statistical analysis in academia, medicine, economics and social science;
  • charts, dashboards and reports that update when the data changes;
  • machine learning and forecasting;
  • reproducible documents that mix text, code and results.

R compared with other tools

R Python Spreadsheet
Built for Statistics and data analysis General programming Manual tables and quick sums
Repeating an analysis Run the script again Run the script again Redo clicks or fragile macros
Statistics out of the box Very strong Needs libraries Basic
Charts Excellent (ggplot2) Excellent (matplotlib, seaborn) Basic to moderate
Learning curve Moderate Moderate Gentle

R and Python are not rivals you must choose between. Many data teams use both. If you already know Python, you will recognize most ideas in this course, and we point out the differences where they matter. A spreadsheet is fine for a quick look, but a script documents every step, so another person (or you in six months) can repeat the work exactly.

Your first taste of R

You do not need to understand every symbol yet. Read these lines as a preview:

R
# Add two numbers
2 + 3
#> [1] 5

# Store a value in a variable, then use it
price <- 19.99
price * 3
#> [1] 59.97

# Work with several numbers at once
scores <- c(72, 88, 95, 61)
mean(scores)
#> [1] 79

Things to notice:

  1. # starts a comment. R ignores the rest of the line.
  2. <- is the assignment arrow. It stores the value on the right in the name on the left.
  3. c() combines values into a vector.
  4. The [1] in the output means "this line starts with element number 1". It is a position marker, not part of the answer.

In this course, lines that start with #> show the output R prints. You do not type them.

How an R project flows

Nearly every analysis follows the same path, whatever the topic:

flowchart LR
    A["Import<br/>read data in"] --> B["Tidy and clean<br/>fix types, missing values"]
    B --> C["Transform<br/>filter, group, summarize"]
    C --> D["Visualize<br/>charts"]
    C --> E["Model<br/>statistics"]
    D --> F["Communicate<br/>reports"]
    E --> F

Figure: the usual stages of an R analysis. Chapters 4 to 7 of this course follow this path.

You can think of R as a workshop. Data frames are the workbench, functions are the tools, and packages are extra toolboxes you bring in when you need them.

The shape of this course

What you will learn

Foundations Vectors, lists, factors
Programming Functions and loops
Data work Data frames and dplyr
Insight Charts and models

Each chapter builds on the last.

1 / 2

A few honest warnings

R has quirks that surprise newcomers. Knowing them early saves frustration:

  • Counting starts at 1. The first element of a vector is x[1], not x[0].
  • Names are case sensitive. Mean and mean are different things.
  • Several ways to do one thing. R has an older "base" style and a newer "tidyverse" style. This course teaches both, because you will meet both in real code.
  • Silent surprises. R often recycles or converts values without complaint. We cover these cases carefully in Data Types and Coercion.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What was R mainly designed for?

    R was created by statisticians and is built around data, statistics and visualization.
  2. 2. What does [1] at the start of an output line mean?

    It is a position marker. Long vectors wrap over several lines, each starting with the index of its first element.
  3. 3. Which symbol is the usual way to assign a value in R?

    <- is the conventional assignment operator. = also works in most places, but <- is the standard style.
  4. 4. Why are the R snippets on this site not runnable in the page?

    The site's in-browser runners do not include R, so the code is shown read-only and you run it locally.

Summary

  • R is a language and environment for data analysis, statistics and graphics.
  • Vectors and built-in statistics are at its core; packages extend it.
  • A typical project imports, cleans, transforms, visualizes and models data, then reports the results.
  • <- assigns, c() combines, # comments, and counting starts at 1.
  • Code here is read-only; run it in your own R installation.

Next: Install R and RStudio