# Getting started with R

2 min read
Table of Contents

R is a programming language designed for statistical computing and data visualization. It’s widely used in data science, research, and academia. This guide walks you through installing R, exploring its basics, and performing a simple analysis.

Installing R

1. Install R

Download R from the Comprehensive R Archive Network (CRAN):
https://cran.r-project.org

Choose the installer for your operating system and follow the prompts.

RStudio is a popular integrated development environment (IDE) for R. Download it here:
https://posit.co/download/rstudio-desktop/

Running R

You can run R:

  • In the RStudio console
  • Directly in the terminal by typing R
  • In scripts saved as .R files

Basic Syntax

# Assign variables
x <- 5
y <- 10
# Print output
print(x + y)
# Create a vector
numbers <- c(1, 2, 3, 4, 5)
# Get the mean
mean(numbers)

Data Structures

  • Vector: One-dimensional array of elements of the same type.
  • Matrix: Two-dimensional array.
  • Data Frame: Table-like structure (similar to a spreadsheet).
  • List: Collection of elements of different types.

Example of a data frame:

data <- data.frame(
name = c("Alice", "Bob"),
age = c(25, 30)
)
print(data)

Installing and Loading Packages

Packages extend R’s functionality.

install.packages("ggplot2")
library(ggplot2)

Plotting Data

library(ggplot2)
df <- data.frame(
x = 1:10,
y = c(2, 3, 5, 7, 11, 13, 17, 19, 23, 29)
)
ggplot(df, aes(x = x, y = y)) +
geom_point() +
geom_line() +
labs(title = "Simple Plot", x = "X values", y = "Y values")

Reading Data from a CSV

data <- read.csv("data.csv")
head(data)

Performing a Simple Analysis

summary(data)
cor(data$x, data$y)

Tips for Learning R

  • Practice with built-in datasets (mtcars, iris).
  • Learn vectorized operations instead of loops when possible.
  • Explore R’s extensive package ecosystem for specialized analysis.

Final Thoughts

R is an excellent choice for statistics and visualization. Once you’re comfortable with the basics, explore tidyverse packages for modern, streamlined data analysis.

My avatar

Thanks for reading my blog post! Feel free to check out my other posts or contact me via the social links in the footer.


More Posts