-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
79 lines (79 loc) · 1.92 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
19.21 * .15
19.71 * .15
install.packages("dslabs")
install.packages("tidyverse")
library(tidyverse)
library(dslabs)
data("murders")
murders %>%
source("C:/Users/reday/Documents/harvard-r-basics/first_script.R", echo=TRUE)
setwd("~/harvard-r-basics")
library(dslabs)
data(murders)
murders$state[which.max(murders$population)]
max(murders$population)
max(murders$population) # The max value of population
heights <- random(69:80)
heights <- rando(69:80)
heights <- rand(69:80)
heights <- c(69, 454, 435, 5, 34, 523, 4, 32, 4, 4, 32, 453, 2, 43, 24, 3, 24, 23)
heights * 2.54
heights - 69 # Subtracts 69 from each element in the vector
murder_rate <- murders$total / murders$population
murder_rate
murder_rate <- (murders$total / murders$population) * 100,000
murder_rate <- (murders$total / murders$population) * 100_000
murder_rate <- (murders$total / murders$population) * 100000
murder_rate
order(murder_rate)
murder_rate <- (murders$total / murders$population) * 100000 # The object murder_rate is storing the result of the total murders divided by the population, times 100000 for units
murder_rate
mr_ind <- order(murder_rate)
murders$state[mr_ind]
mr_max <- which.max(murder_rate)
murders$state[mr_max]
murders$state[order(murder_rate, decrease=TRUE)]
murder_rate
murders$state[order(murder_rate, decrease=TRUE)]
murders$state[order(murder_rate, decreasing =TRUE)]
x <- c(2, 43, 27, 96, 18)
rank(x)
sort(x)
order(x)
min(x)
x <- c(2, 43, 27, 96, 18)
min(x)
which.min(x)
max(x)
which.max(x)
x <- c(2, 43, 27, 96, 18)
min(x)
which.min(x)
max(x)
which.max(x)
time /60
time / 60
time/60
time * 60
# Question 1
x <- c(2, 43, 27, 96, 18)
rank(x)
sort(x)
order(x)
# Question 2
x <- c(2, 43, 27, 96, 18)
min(x)
which.min(x)
max(x)
which.max(x)
# Question 3
name <- c("Mandi", "Amy", "Nicole", "Olivia")
distance <- c(0.8, 3.1, 2.8, 4.0)
time <- c(10, 30, 40, 50)
time * 60
time_hr <- time / 60
names(name) <- time_hr
name
mph <- distance / time_hr
names(name) <- mph
name