# Read the StudentSurvey.csv in here
student_sur <- read.csv("StudentSurvey.csv")DATA 101 — Homework 2: Student Survey
Set the working directory:
- Download “StudentSurvey.csv” to your computer.
- Set Working directory to the folder you saved your file in.
- Read the file using read.csv command.
Instructions:
Read the StudentSurvey into this document and answer the following questions.
Check the data structure:
# Check the head of the data set
head(student_sur) Year Sex Smoke Award HigherSAT Exercise TV Height Weight Siblings
1 Senior M No Olympic Math 10 1 71 180 4
2 Sophomore F Yes Academy Math 4 7 66 120 2
3 FirstYear M No Nobel Math 14 5 72 208 2
4 Junior M No Nobel Math 3 1 63 110 1
5 Sophomore F No Nobel Verbal 3 3 65 150 1
6 Sophomore F No Nobel Verbal 5 4 65 114 2
BirthOrder VerbalSAT MathSAT SAT GPA Pulse Piercings
1 4 540 670 1210 3.13 54 0
2 2 520 630 1150 2.50 66 3
3 1 550 560 1110 2.55 130 0
4 1 490 630 1120 3.10 78 0
5 1 720 450 1170 2.70 40 6
6 2 600 550 1150 3.20 80 4
# Check the dimensions
dim(student_sur)[1] 362 17
# Check the structure (str) of the dataset.
# Name one numeric variable and one categorical variable below:
str(student_sur)'data.frame': 362 obs. of 17 variables:
$ Year : chr "Senior" "Sophomore" "FirstYear" "Junior" ...
$ Sex : chr "M" "F" "M" "M" ...
$ Smoke : chr "No" "Yes" "No" "No" ...
$ Award : chr "Olympic" "Academy" "Nobel" "Nobel" ...
$ HigherSAT : chr "Math" "Math" "Math" "Math" ...
$ Exercise : num 10 4 14 3 3 5 10 13 3 12 ...
$ TV : int 1 7 5 1 3 4 10 8 6 1 ...
$ Height : int 71 66 72 63 65 65 66 74 61 60 ...
$ Weight : int 180 120 208 110 150 114 128 235 NA 115 ...
$ Siblings : int 4 2 2 1 1 2 1 1 2 7 ...
$ BirthOrder: int 4 2 1 1 1 2 1 1 2 8 ...
$ VerbalSAT : int 540 520 550 490 720 600 640 660 550 670 ...
$ MathSAT : int 670 630 560 630 450 550 680 710 550 700 ...
$ SAT : int 1210 1150 1110 1120 1170 1150 1320 1370 1100 1370 ...
$ GPA : num 3.13 2.5 2.55 3.1 2.7 3.2 2.77 3.3 2.8 3.7 ...
$ Pulse : int 54 66 130 78 40 80 94 77 60 94 ...
$ Piercings : int 0 3 0 0 6 4 8 0 7 2 ...
Numeric variable: Weight______
Categorical variable: Sex______
# Create a table of students' sex and "HigherSAT"
table(student_sur$Sex,student_sur$HigherSAT)
Math Verbal
F 4 81 84
M 3 124 66
# Display summary statistics for VerbalSAT
summary(student_sur$VerbalSAT) Min. 1st Qu. Median Mean 3rd Qu. Max.
390.0 550.0 600.0 594.2 640.0 800.0
# Find the average GPA of students
mean(student_sur$GPA,na.rm = TRUE)[1] 3.157942
# Create a new dataframe, call it "column_df". This new dataframe should contain students' weight and number of hours they exercise
column_df <- student_sur[c("Weight", "Exercise")]# Access the fourth element in the first column from the StudentSurvey's dataset
student_sur[4,1][1] "Junior"
# How many students report an exercise time of more than 10 hours per week?
sum(student_sur$Exercise > 10, na.rm = TRUE)[1] 123