1. What is R?
R is an open-source programming language and software environment developed for statistical computing, graphics, reporting and data analysis. It was created by Ross Ihaka and Robert Gentleman and is maintained by the R Development Core Team.
- Statistical analysis and reporting
- Data cleaning and visualization
- Cross-platform (Windows, Linux, macOS)
- Extensible through thousands of CRAN packages
- Integrates with C, C++, Python, Java and others
Learning Objectives
Define R, explain its features and describe why it is widely used in research and industry.
Define R, explain its features and describe why it is widely used in research and industry.
Example
2 + 3
marks <- c(78,85,90,67)
marks
mean(marks)
x <- c(1,2,3,4)
y <- c(2,4,6,8)
plot(x,y,type="b",main="Simple Line Plot")
2. Why Use R?
- Free and open source (GNU GPL)
- Excellent statistical computing
- Professional graphics
- Interactive data exploration
- Large package ecosystem
- Object-oriented programming support
Industry Usage
- Twitter – user experience analytics
- Ford – social media analysis
- The New York Times – data journalism
- Google – internal analytics and style guide
- Microsoft – enterprise R distributions
Common Misconceptions
- R is more than a statistics package.
- Beginners can learn R easily.
- Vectors and data frames reduce the need for complex loops.
3. Installing R and RStudio
- Visit https://www.r-project.org
- Open CRAN.
- Download R for Windows.
- Install using default settings.
- Download RStudio (Posit).
- Install and launch RStudio.
print("R is installed and working!")
R.version.string
2+2
getwd()
Remember: RStudio is an IDE. R must be installed first.
4. Student Survey Analysis Workflow
Workflow:
Load Data → Clean Data → Calculate Statistics → Create Graphs → Interpret Results
Sample Dataset
| ID | Gender | Attendance | Theory | Lab | Rating |
|---|---|---|---|---|---|
| 101 | Male | 92 | 84 | 90 | 5 |
| 102 | Female | 88 | 76 | 82 | 4 |
| 103 | Male | 65 | 58 | 62 | 3 |
| 104 | Female | NA | 81 | 85 | 5 |
| 105 | Male | 95 | 91 | 94 | 5 |
Step 0 - Load Data
setwd("C:/Users/Student/Documents")
getwd()
survey <- read.csv("student_survey.csv")
head(survey)
Step 1 - Clean Data
is.na(survey$Attendance)
sum(is.na(survey$Attendance))
avg_attendance <- mean(survey$Attendance,na.rm=TRUE)
survey$Attendance[is.na(survey$Attendance)] <- avg_attendance
Step 2 - Statistics
mean(survey$TheoryMarks)
mean(survey$LabMarks)
mean(survey$CourseRating)
sd(survey$TheoryMarks)
summary(survey)
Step 3 - Visualization (ggplot2)
install.packages("ggplot2")
library(ggplot2)
ggplot(survey,aes(x=Gender,y=TheoryMarks))+
stat_summary(fun=mean,geom="bar")
ggplot(survey,aes(x=TheoryMarks))+geom_histogram(binwidth=5)
ggplot(survey,aes(x=Gender,y=TheoryMarks))+geom_boxplot()
ggplot(survey,aes(x=Attendance,y=TheoryMarks))+geom_point(size=3)
Step 4 - Interpretation
- Missing attendance replaced using average.
- Average theory marks ≈ 80.
- Average course rating = 4.3/5.
- Higher attendance generally corresponds to higher theory marks.
- No major outliers observed.
Summary
Week 1 introduced R, explained why it is popular, demonstrated installation of R and RStudio, and completed a practical data analysis workflow including importing CSV data, cleaning missing values, computing statistics, visualizing results with ggplot2, and interpreting findings.