This repository has been archived by the owner on Jan 17, 2023. It is now read-only.
forked from Datapolitan-Training/data-analysis-r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
faithful_a.R
77 lines (41 loc) · 1.48 KB
/
faithful_a.R
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
# Faithful Exercise
# Goal: Explore R Studio and basic commands in R
# Directions: Run through line by line.
# Use ? if you get lost, ask a neighbor, or raise your hand
# Open dataset
View(faithful)
?faithful
# Syntax Error!
view(faithful)
# Explore dataset
nrow(faithful)
ncol(faithful)
colnames(faithful)
head(faithful)
# Understand data structure
str(faithful)
class(faithful$eruptions)
class(faithful$waiting)
# Calculate summary statistics
min(faithful$waiting)
max(faithful$waiting)
mean(faithful$waiting)
median(faithful$waiting)
summary(faithful)
# Visualize data
hist(faithful$waiting)
hist(faithful$eruptions)
plot(faithful, main="Eruptions of Old Faithful", xlab="Eruption Time in Minutes", ylab="Waiting Time to Next Eruption in Min")
abline(lm(faithful$waiting~faithful$eruptions), col="red")
# Now we want to work on sorting and filtering the data we had above
# Sorting by eruption times (ascending)
# Sorting by eruption times (descending)
# Filter for waiting times greater than 80
# How many instances (rows) have a waiting time greater than 80 (look at our examples above)
# What about waiting times greater than 30?
# Sort now by waiting time (ascending)
# Sort now by waiting time (descending)
# Sort by first Waiting Time and then Eruptions
# Sort by first Eruptions and then Waiting Time
# Filter for eruptions greater than or equal to 4 mintues
# Filter on two criteria (greater than or equal to 4 mins and waiting time greater than or equal to 70)