R Setup Guide
This guide will get you set up with R for Statistics 224.
๐ Recommended: Posit Cloud
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
- Go to: posit.cloud
- Sign up with your school email
- Create a new project
- 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
Step 2: Install RStudio
- Go to posit.co/download/rstudio-desktop
- Download RStudio Desktop (Free)
- Install with default settings
- 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:
"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
- R for Data Science (free online book)
- RStudio Cheatsheets
- Our Interactive Modules
โ 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