#If your assignment does not render, you might need to install.packages("htmltools")
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.1 ✔ stringr 1.5.2
## ✔ ggplot2 4.0.0 ✔ tibble 3.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
setwd("C:/Users/spend/Desktop/DATA SCIENCE/DATA SET FOLDER")
student_survey <- read.csv("studentsurvey.csv")
Read the StudentSurvey into this markdown and answers the following questions
#read the StudentSurvey.csv in here
student_survey
## 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
## 7 FirstYear F No Olympic Math 10 10 66 128 1
## 8 Sophomore M No Olympic Math 13 8 74 235 1
## 9 FirstYear F No Nobel Math 12 1 60 115 7
## 10 Sophomore F No Olympic Math 12 6 65 140 1
## 11 Junior F No Nobel Verbal 6 1 68 135 2
## 12 FirstYear F No Olympic Math 10 2 63 110 1
## 13 FirstYear F No Olympic Verbal 3 15 63 99 2
## 14 Sophomore M No Nobel Verbal 7 3 72 165 2
## 15 Sophomore F No Nobel Math 2 1 62 120 1
## 16 Sophomore F No Olympic Verbal 14 2 67 154 1
## 17 Sophomore F No Nobel Math 10 5 65 110 1
## 18 Sophomore F No Nobel Math 14 2 68 145 8
## 19 FirstYear M No Olympic Math 20 20 73 195 3
## 20 Sophomore M No Olympic Math 7 10 74 200 1
## 21 Sophomore M No Olympic Math 12 3 70 167 1
## 22 Sophomore M No Nobel Math 10 5 71 175 3
## 23 Sophomore F No Academy Verbal 6 8 67 155 1
## 24 Junior M No Nobel Math 14 2 74 185 1
## 25 FirstYear M No Olympic Math 12 6 68 190 1
## 26 Senior M No Olympic Verbal 10 4 72 165 1
## 27 Junior M No Academy Math 8 8 62 175 2
## 28 Sophomore F No Nobel Math 0 2 66 126 5
## 29 FirstYear M No Olympic Math 10 20 70 187 3
## 30 Senior M No Nobel Verbal 6 10 72 170 2
## 31 FirstYear F No Olympic Math 5 2 67 158 4
## 32 Sophomore F No Olympic Math 24 5 62 119 1
## 33 FirstYear M No Olympic Math 2 5 73 205 1
## 34 Sophomore F No Academy Math 10 5 67 129 1
## 35 Sophomore F No Academy Verbal 6 5 67 145 0
## 36 Junior F No Nobel Verbal 5 5 64 130 0
## 37 Senior M No Nobel Verbal 5 5 72 215 3
## 38 Sophomore F No Nobel Verbal 12 4 64 135 2
## 39 Sophomore F No Olympic Verbal 2 5 70 145 0
## 40 FirstYear F No Olympic Math 7 8 60 98 2
## 41 FirstYear M No Olympic Math 15 2 71 150 1
## 42 Junior M No Olympic Verbal 5 14 73 159 1
## 43 Senior M No Olympic Verbal 7 20 72 174 1
## 44 Sophomore M No Olympic Math 15 20 74 160 1
## 45 Senior M No Olympic Math 8 10 70 165 1
## 46 Sophomore F No Olympic Math 14 3 69 161 1
## 47 Senior F No Nobel Math 4 14 64 130 2
## 48 Junior M No Olympic Math 15 0 72 175 2
## 49 Senior M No Olympic Math 4 20 70 255 2
## 50 Junior M No Olympic Verbal 15 2 65 160 4
## 51 FirstYear M No Academy Verbal 3 6 72 160 0
## 52 Junior F No Academy Math 3 15 63 95 0
## 53 Sophomore F No Olympic Math 15 3 64 115 2
## 54 Sophomore F No Academy Math 20 2 64 120 1
## 55 FirstYear F No Nobel Verbal 3 1 65 135 2
## 56 Sophomore M No Academy Math 6 7 73 180 1
## 57 Senior M No Nobel Math 12 7 71 155 0
## 58 FirstYear F No Olympic Verbal 4 3 66 110 2
## 59 FirstYear M No Olympic Verbal 20 12 73 215 2
## 60 Sophomore F No Olympic Math 10 3 65 140 3
## 61 FirstYear M No Olympic Verbal 10 20 72 195 2
## 62 Sophomore M No Nobel Verbal 4 8 73 185 2
## 63 Sophomore M No Nobel Verbal 9 0 70 185 2
## 64 Senior M No Olympic Verbal 12 12 79 209 1
## 65 Senior F No Olympic Math 2 6 67 145 3
## 66 FirstYear F Yes Nobel Verbal 2 1 68 180 2
## 67 Senior M Yes Nobel Math 5 25 69 170 1
## 68 Sophomore F Yes Olympic Math 5 3 66 135 3
## 69 FirstYear M Yes Olympic Math 6 25 72 165 2
## 70 Sophomore F Yes Nobel Math 10 10 65 137 0
## 71 Sophomore M Yes Nobel Math 4 1 70 147 2
## 72 Senior F Yes Olympic Math 5 4 66 150 1
## 73 Junior F Yes Nobel Math 17 2 67 155 2
## 74 Sophomore M Yes Nobel Verbal 7 10 71 160 2
## 75 Sophomore F Yes Nobel Verbal 2 0 83 130 1
## 76 Sophomore M Yes Olympic Math 8 10 61 180 2
## 77 Sophomore F Yes Nobel Verbal 1 1 65 150 2
## 78 FirstYear M Yes Olympic Verbal 14 5 77 205 2
## 79 Sophomore F Yes Olympic Math 12 5 60 115 0
## 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
## 7 1 640 680 1320 2.77 94 8
## 8 1 660 710 1370 3.30 77 0
## 9 8 670 700 1370 3.70 94 2
## 10 2 500 670 1170 2.09 63 2
## 11 3 650 650 1300 3.08 66 4
## 12 2 590 610 1200 3.86 59 4
## 13 1 600 600 1200 3.00 88 4
## 14 1 700 650 1350 3.00 59 0
## 15 1 610 800 1410 3.35 64 2
## 16 2 550 450 1000 3.30 72 5
## 17 2 550 640 1190 3.40 74 2
## 18 8 560 570 1130 2.90 70 2
## 19 4 560 620 1180 3.50 58 0
## 20 2 550 650 1200 3.00 48 0
## 21 2 550 680 1230 3.30 74 0
## 22 2 700 720 1420 3.70 60 0
## 23 1 610 590 1200 3.48 74 2
## 24 2 570 580 1150 3.40 70 0
## 25 1 550 560 1110 2.50 74 0
## 26 2 500 500 1000 3.30 60 0
## 27 3 610 620 1230 3.50 55 0
## 28 6 610 650 1260 3.79 82 1
## 29 2 500 560 1060 3.30 68 0
## 30 2 640 640 1280 2.90 83 0
## 31 2 490 520 1010 2.68 53 2
## 32 2 560 580 1140 3.28 72 4
## 33 1 560 640 1200 3.51 86 0
## 34 1 470 600 1070 2.60 67 4
## 35 1 680 670 1350 3.85 89 2
## 36 NA 570 570 1140 2.40 48 4
## 37 1 630 590 1220 3.40 64 0
## 38 3 580 540 1120 2.40 73 7
## 39 1 550 500 1050 3.00 80 2
## 40 2 490 550 1040 3.10 85 5
## 41 1 590 650 1240 2.94 60 0
## 42 1 620 620 1240 3.31 61 0
## 43 2 560 550 1110 3.30 80 0
## 44 2 630 690 1320 2.90 70 0
## 45 2 600 630 1230 3.40 61 0
## 46 2 550 650 1200 3.16 58 2
## 47 2 640 730 1370 3.84 88 4
## 48 1 650 670 1320 3.60 68 1
## 49 2 420 520 940 2.36 68 0
## 50 4 500 480 980 2.90 35 0
## 51 1 620 600 1220 3.00 90 0
## 52 1 600 660 1260 3.30 88 4
## 53 2 580 680 1260 3.70 67 2
## 54 1 490 520 1010 2.90 71 2
## 55 3 630 620 1250 3.60 68 2
## 56 2 600 670 1270 3.56 73 0
## 57 1 590 610 1200 3.70 55 2
## 58 1 550 520 1070 4.00 78 5
## 59 3 600 600 1200 3.40 96 0
## 60 4 600 650 1250 3.30 73 5
## 61 2 600 600 1200 3.10 60 1
## 62 1 650 530 1180 2.50 80 0
## 63 1 650 650 1300 3.20 96 0
## 64 1 560 520 1080 3.10 49 0
## 65 2 540 640 1180 3.50 62 5
## 66 3 680 610 1290 3.25 80 5
## 67 1 500 650 1150 3.30 70 0
## 68 2 570 580 1150 3.25 78 4
## 69 1 540 550 1090 2.83 75 0
## 70 1 550 560 1110 3.30 42 5
## 71 2 680 750 1430 3.60 80 0
## 72 2 630 730 1360 3.70 72 2
## 73 1 650 670 1320 2.83 96 6
## 74 3 680 650 1330 3.30 95 0
## 75 1 550 540 1090 3.44 80 3
## 76 1 600 620 1220 3.00 74 0
## 77 2 540 450 990 3.27 78 2
## 78 2 550 550 1100 2.30 72 0
## 79 1 500 510 1010 2.60 91 5
student_sur_df <- student_survey
#check the head of the data set
head(student_sur_df)
## 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_df)
## [1] 79 17
#create a table of students'sex and "HigherSAT"
xtabs(~ Sex + HigherSAT, data=student_sur_df)
## HigherSAT
## Sex Math Verbal
## F 25 15
## M 24 15
table(student_sur_df$Sex, student_sur_df$HigherSAT)
##
## Math Verbal
## F 25 15
## M 24 15
table(student_sur_df$HigherSAT, student_sur_df$Sex)
##
## F M
## Math 25 24
## Verbal 15 15
# Display summary statistics for VerbalSAT
summary(student_sur_df$VerbalSAT)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 420.0 550.0 580.0 583.2 630.0 720.0
#Find the average GPA of students
mean(student_sur_df$GPA)
## [1] 3.169114
#Create a new dataframe, call it "column_df". This new dataframe should contain students' weight and number of hours the exercise
column_df <- data.frame(weight = student_sur_df$Weight, Hours = student_sur_df$Exercise)
column_df
## weight Hours
## 1 180 10
## 2 120 4
## 3 208 14
## 4 110 3
## 5 150 3
## 6 114 5
## 7 128 10
## 8 235 13
## 9 115 12
## 10 140 12
## 11 135 6
## 12 110 10
## 13 99 3
## 14 165 7
## 15 120 2
## 16 154 14
## 17 110 10
## 18 145 14
## 19 195 20
## 20 200 7
## 21 167 12
## 22 175 10
## 23 155 6
## 24 185 14
## 25 190 12
## 26 165 10
## 27 175 8
## 28 126 0
## 29 187 10
## 30 170 6
## 31 158 5
## 32 119 24
## 33 205 2
## 34 129 10
## 35 145 6
## 36 130 5
## 37 215 5
## 38 135 12
## 39 145 2
## 40 98 7
## 41 150 15
## 42 159 5
## 43 174 7
## 44 160 15
## 45 165 8
## 46 161 14
## 47 130 4
## 48 175 15
## 49 255 4
## 50 160 15
## 51 160 3
## 52 95 3
## 53 115 15
## 54 120 20
## 55 135 3
## 56 180 6
## 57 155 12
## 58 110 4
## 59 215 20
## 60 140 10
## 61 195 10
## 62 185 4
## 63 185 9
## 64 209 12
## 65 145 2
## 66 180 2
## 67 170 5
## 68 135 5
## 69 165 6
## 70 137 10
## 71 147 4
## 72 150 5
## 73 155 17
## 74 160 7
## 75 130 2
## 76 180 8
## 77 150 1
## 78 205 14
## 79 115 12
#Access the fourth element in the first column from the StudentSurvey's dataset.
student_sur_df[4,1]
## [1] "Junior"