R Programming - Week 1

Introduction, Installation and Student Survey Analysis

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.

Learning Objectives
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?

Industry Usage

Common Misconceptions

3. Installing R and RStudio

  1. Visit https://www.r-project.org
  2. Open CRAN.
  3. Download R for Windows.
  4. Install using default settings.
  5. Download RStudio (Posit).
  6. 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

IDGenderAttendanceTheoryLabRating
101Male9284905
102Female8876824
103Male6558623
104FemaleNA81855
105Male9591945

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

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.