-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
208 lines (208 loc) · 9.05 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
load("~/Documents/Data_Science/R_Analysis/01_Demo/Vehicle analysis.RData")
load("~/Documents/Data_Science/UCSD_BootCamp/Class_Activities/Module15 R/15-1-Student_Resources/01_Ins_RBasics/Solved/01_Ins_RBasics.R")
knitr::opts_chunk$set(echo = TRUE)
summary(cars)
students
# Part I
students <- c("Abraham", "Beatrice", "Cory", "Dinah", "Eric", "Eric")
students
roll_call <- function(class){
print(Sys.Date())
# Create a for loop
for (student in students)
{print (student)}
}
roll_call
roll_call <- function(class){
print(Sys.Date())
# Create a for loop
for (student in students)
{print (student)}
}
# Call the function with the student vector as an argument.
roll_call(students)
locker_combinations <- function(class){
# Create the for loop and print the student name and locker combination.
for (student in students){
print(sample(33,3))
}
}
# Call the function with the student vector as an argument.
locker_combinations(students)
locker_combinations <- function(class){
# Create the for loop and print the student name and locker combination.
for (student in students){
print(sutdent + sample(33,3))
}
}
# Call the function with the student vector as an argument.
locker_combinations(students)
locker_combinations <- function(class){
# Create the for loop and print the student name and locker combination.
for (student in students){
print(student + sample(33,3))
}
}
# Call the function with the student vector as an argument.
locker_combinations(students)
locker_combinations <- function(class){
# Create the for loop and print the student name and locker combination.
for (student in students){
print(student)
print(sample(33,3))
}
}
# Call the function with the student vector as an argument.
locker_combinations(students)
locker_combinations <- function(class){
# Create the for loop and print the student name and locker combination.
for (student in class){
print(student)
print(sample(33,3))
}
}
# Call the function with the student vector as an argument.
locker_combinations(students)
# Part III
for (student in students){
# Create a variable (substring) that holds the second letter for each student.
second_letter <- substring(student,2,2)
# Create an if statement to find the names of students where the
# second letter that is an "e".
if (second_letter == "e")
{
print(student)
print(sample(33:66,3))
}
}
save.image("~/Documents/Data_Science/UCSD_BootCamp/Class_Activities/Module15 R/15-1-Student_Resources/02_Stu_RBasics/Unsolved/high school students.RData")
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
data(diamonds, package='ggplot2')
library(tidyverse)
data(diamonds, package='ggplot2')
nrow(diamonds)
head(diamonds, 10)
tail(diamonds, 10)
slice(diamonds, 1:7)
slice(diamonds, 3)
slice(diamonds, c(1,7))
select(diamonds, carat, price)
filter(diamonds, cut=='Ideal')
filter(diamonds, (cut=='Ideal' & price > 500))
total_volume <- mutate(diamonds, x * y * z)
total_volume
?mutate()
# In R, variables can contain periods
total.volume2 <- mutate(diamonds, total.volume=(x*y*z))
total.volume2
summarize(diamonds, mean(price))
cut <- group_by(diamonds, cut)
summarize(cut, mean(price), sum(price))
summarize(cut, avg=mean(price),number=n())
cut2 <- group_by(diamonds, cut, color)
cut2_summary <- summarize(cut2, mean(price))
cut2_summary
students <- read_csv(students.csv)
load("~/Documents/Data_Science/UCSD_BootCamp/Class_Activities/Module15 R/15-1-Student_Resources/06_Evr_Tibble/Resources/students.csv")
students <- read_csv(students.csv)
students <-read_csv(students.csv)
students <-read_csv(students.csv)
students <-read.csv(students.csv)
students <-read.csv(file='students.csv',check.names=F,stringsAsFactors =F)
students <-read.csv(file='students.csv')
students <-read.csv(students.csv)
students <-read.csv(students.csv)
students <-read_csv(students.csv)
?read_csv()
students <-read_csv('students.csv')
library(tidyverse)
mosquito <- read.csv(file="../Resources/mosquito.csv")
setwd("~/Documents/Data_Science/UCSD_BootCamp/Class_Activities/Module15 R/15-2-Student_Resources/Activities/04-Ins_ANOVA")
mosquito <- read.csv(file="../Resources/mosquito.csv")
setwd("~/Documents/Data_Science/UCSD_BootCamp/Class_Activities/Module15 R/15-2-Student_Resources/Activities/04-Ins_ANOVA/Solved")
mosquito <- read.csv(file="../Resources/mosquito.csv")
ggplot(mosquito,aes(x=factor(treatment),y=mosq)) + geom_boxplot()
# aov performs the analysis of variance, but does not provide a p-value
aov(mosq ~ factor(treatment), data=mosquito)
# to obtain a p-value, wrap aov() with a summary() function
summary(aov(mosq ~ factor(treatment), data=mosquito))
ggplot(mosquito,aes(x=factor(treatment),y=mosq)) + geom_boxplot()
# aov performs the analysis of variance, but does not provide a p-value
aov(mosq ~ factor(treatment), data=mosquito)
# to obtain a p-value, wrap aov() with a summary() function
summary(aov(mosq ~ factor(treatment), data=mosquito))
qplot(mosquito, geom = 'bar')
View(mosquito)
typeof(mosquito)
typeof(treatment)
treatment_fct <- factor(treatment)
treatment_fct <- factor(mosquito$treatment)
typeof(treatment_fct)
summary(treatment_fct)
qplot(treatment_fct, geom='bar')
setwd("~/Documents/Data_Science/UCSD_BootCamp/Module_Projects/MechaCar_Statistical_Analysis")
library(dplyr)
MechaCar <- read.csv(MechaCar_mpg.csv)
MechaCar <- read.csv("MechaCar_mpg.csv")
View(mosquito)
MechaCar <- read.csv("MechaCar_mpg.csv")
View(MechaCar)
?lm()
lm(mpg ~ vehicle_lenght + vehicle_weight + spoiler_angle + ground_clearance + AWD, data = MechaCar_mpg)
lm(mpg ~ vehicle_lenght + vehicle_weight + spoiler_angle + ground_clearance + AWD, data = MechaCar)
lm(mpg ~ vehicle_length + vehicle_weight + spoiler_angle + ground_clearance + AWD, data = MechaCar)
summary(lm(mpg ~ vehicle_length + vehicle_weight + spoiler_angle + ground_clearance + AWD, data = MechaCar)) #ge
summary(lm(mpg ~ vehicle_length + vehicle_weight + spoiler_angle + ground_clearance + AWD, data = MechaCar))
Suspension_Coil <- read.csv("Suspension_Coil")#import Suspension_Coil dataset
Suspension_Coil <- read.csv("Suspension_Coil.csv")#import Suspension_Coil dataset
summarize(Suspension_Coil)
View(Suspension_Coil)
View(Suspension_Coil)
?summarize
summarise(Suspension_Coil)
summarize(Suspension_Coil$PSI)
total_summary <- summarize(Suspension_Coil$PSI)
total_summary <- summarize(Mean=mean(Suspension_Coil$PSI))
total_summary <- summarize(Suspension_Coil[['PSI']])
class(Suspension_Coil$PSI)='Integer'
total_summary <- summarize(Suspension_Coil$PSI)
total_summary <- Suspension_Coil %>% summarize(Mean=mean('PSI'))
class(Suspension_Coil$PSI)='Numeric'
total_summary <- Suspension_Coil %>% summarize(Mean=mean('PSI'))
class(Suspension_Coil$PSI)='numeric'
total_summary <- Suspension_Coil %>% summarize(Mean=mean('PSI'))
typeof(Suspension_Coil$PSI)
Suspension_Coil <- read.csv("Suspension_Coil.csv")#import Suspension_Coil dataset
typeof(Suspension_Coil$PSI)
mean(Suspension_Coil$PSI)
summary(Suspension_Coil$PSI)
total_summary <- Suspension_Coil %>% summarize(Mean=mean('PSI'))
total_summary <- Suspension_Coil %>% summarize(Mean=mean(PSI))
total_summary <- Suspension_Coil %>% summarize(Mean=mean(PSI),Median=median(PSI),Variance=varianc(PSI),SD=sd(PSI))
total_summary <- Suspension_Coil %>% summarize(Mean=mean(PSI),Median=median(PSI),Variance=variance(PSI),SD=sd(PSI))
total_summary <- Suspension_Coil %>% summarize(Mean=mean(PSI),Median=median(PSI),Variance=var(PSI),SD=sd(PSI))
total_summary
View(total_summary)
lot_summary <- Suspension_Coil %>% group_by(Manfaturing_Lot) %>% summarize(Mean=mean(PSI),Median=median(PSI),Variance=var(PSI),SD=sd(PSI), .group = 'keep')#
lot_summary <- Suspension_Coil %>% group_by(Manufaturing_Lot) %>% summarize(Mean=mean(PSI),Median=median(PSI),Variance=var(PSI),SD=sd(PSI), .group = 'keep')#create summary table with multiple columns
lot_summary <- Suspension_Coil %>% group_by(Manufacturing_Lot) %>% summarize(Mean=mean(PSI),Median=median(PSI),Variance=var(PSI),SD=sd(PSI), .group = 'keep')#create summary table with multiple columns
View(lot_summary)
lot_summary <- Suspension_Coil %>% group_by(Manufacturing_Lot) %>% summarize(Mean=mean(PSI),Median=median(PSI),Variance=var(PSI),SD=sd(PSI), .groups = 'keep')#create summary tabl
?t.test
t.test(Suspension_Coil,mu=1500)#compare all manufacture lots versus population mean.
t.test(Suspension_Coil$PSI,mu=1500)#compare PSI of all manufacture lots versus population mean.
t.test((subset(Suspension_Coil$Manufacturing_Lot=='Lot1'))$PSI,mu=1500)
?subset()
lot1 <- subset(Suspension_Coil$Manufacturing_Lot=='Lot1')
lot1 <- subset(Suspension_Coil, Manufacturing_Lot=='Lot1')
t.test(lot1$PSI,mu=1500)
lot1 <- subset(Suspension_Coil, Manufacturing_Lot=='Lot1')#create subset table of Lot1
t.test(lot1$PSI,mu=1500)#compare PSI of Lot1 versus population mean.
lot2 <- subset(Suspension_Coil, Manufacturing_Lot=='Lot2')#create subset table of Lot2
t.test(lot2$PSI,mu=1500)#compare PSI of Lot2 versus population mean.
lot3 <- subset(Suspension_Coil, Manufacturing_Lot=='Lot3')#create subset table of Lot3
t.test(lot3$PSI,mu=1500)#compare PSI of Lot3 versus population mean.
View(lot1)
save.image("~/Documents/Data_Science/UCSD_BootCamp/Module_Projects/MechaCar_Statistical_Analysis/MechaCar_Challenge.RData")
t.test(Suspension_Coil$PSI,mu=1500)#compare PSI of all manufacture lots versus population mean