Skip to content

R Setup Guide

This guide will get you set up with R for Statistics 224.

Best for: Everyone, especially beginners

Why Posit Cloud?

โœ“ No installation needed
โœ“ Works on any computer (even Chromebooks)
โœ“ Consistent environment for everyone
โœ“ Access from anywhere
โœ“ Free tier available

Setup Steps

  1. Go to: posit.cloud
  2. Sign up with your school email
  3. Create a new project
  4. You're ready!

That's it!

Posit Cloud comes with R and RStudio pre-installed. No configuration needed.


๐Ÿ’ป Alternative: Install Locally

Best for: Advanced users who want offline access

Step 1: Install R

  1. Go to CRAN
  2. Click "Download R for Windows"
  3. Click "base"
  4. Download and run the installer
  5. Accept all defaults
  1. Go to CRAN
  2. Click "Download R for macOS"
  3. Download the .pkg file
  4. Open and install
  5. Accept all defaults
# Ubuntu/Debian
sudo apt update
sudo apt install r-base

# Fedora
sudo dnf install R

Step 2: Install RStudio

  1. Go to posit.co/download/rstudio-desktop
  2. Download RStudio Desktop (Free)
  3. Install with default settings
  4. Launch RStudio

๐Ÿ“ฆ Essential Packages

Install these packages in R:

# Copy and paste this into R console
install.packages(c(
  "tidyverse",    # Data manipulation
  "effsize",      # Effect sizes
  "effectsize",   # More effect sizes
  "car",          # ANOVA tools
  "lsr",          # Additional stats
  "psych"         # Descriptive stats
))

Run Once

You only need to install packages once. After that, load them with library().


๐Ÿงช Test Your Setup

Quick Test

Run this code to verify everything works:

# Create some data
x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 6, 8, 10)

# Simple plot
plot(x, y, main = "Test Plot", col = "blue", pch = 19)

# Simple statistics
mean(x)
sd(y)
cor(x, y)

# If this runs without errors, you're good! โœ“

Expected output: - A plot with blue dots - Numbers printed: 3, 2.236..., 1


๐Ÿ“‚ Organizing Your Work

Create Project Structure

Stats224/
โ”œโ”€โ”€ data/           # Your datasets
โ”œโ”€โ”€ scripts/        # R code files
โ”œโ”€โ”€ output/         # Plots and results
โ””โ”€โ”€ notes/          # Your notes

Best Practices

R Tips

  • Use R Scripts (.R files) not console
  • Comment your code with #
  • Save frequently
  • Use meaningful variable names
  • One analysis per script

๐Ÿ”ง RStudio Interface

Main Panels

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Source (Scripts)    โ”‚ Environment/History โ”‚
โ”‚                     โ”‚                     โ”‚
โ”‚ Your code here      โ”‚ Your data objects   โ”‚
โ”‚                     โ”‚                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Console             โ”‚ Files/Plots/Help    โ”‚
โ”‚                     โ”‚                     โ”‚
โ”‚ Code runs here      โ”‚ Output appears here โ”‚
โ”‚                     โ”‚                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Keyboard Shortcuts

Action Windows/Linux Mac
Run line Ctrl+Enter Cmd+Enter
New script Ctrl+Shift+N Cmd+Shift+N
Save Ctrl+S Cmd+S
Comment/Uncomment Ctrl+Shift+C Cmd+Shift+C

๐Ÿ“ฅ Loading Data

From CSV File

# If file is in your working directory:
data <- read.csv("mydata.csv")

# Check it loaded correctly:
head(data)      # First 6 rows
str(data)       # Structure
summary(data)   # Descriptive stats

Example Datasets

R comes with built-in datasets for practice:

# Load built-in dataset
data(mtcars)

# Explore it
?mtcars         # Help file
head(mtcars)    # Preview
names(mtcars)   # Variable names

๐Ÿ†˜ Common Issues

"Package not found"

Solution: Install it first:

install.packages("package_name")

"Object not found"

Solution: Check spelling, make sure you created it first

"Cannot open file"

Solution: Check file path, use getwd() to see working directory

Console shows + instead of >

Solution: You have incomplete code. Press Esc to cancel.


๐Ÿ’ก Learning Resources

Within R

?function_name   # Help for a function
??search_term    # Search all help files
help.start()     # Open help browser

External Resources


โœ… Setup Checklist

[ ] R installed (or Posit Cloud account created)
[ ] RStudio running
[ ] Essential packages installed
[ ] Test code runs successfully
[ ] Project folder created
[ ] Ready to start analyzing!

Next: Getting Started Guide | Decision Tree