Problem 1a) (min and max)
x<-c(2413, 20310, 12637, 2753, 14505, 14440, 2379, 447, 345, 4784, 13803, 12668, 1235, 1257, 1671, 4041, 4145,535, 5270, 3360, 3489, 1979, 2302, 807, 1772, 12807, 5427, 13147, 6288, 1803, 13167, 5343, 6684, 3508, 1549,4975, 11249, 3213, 811, 3560, 7244, 6643, 8571, 13534, 4395, 5729, 14417, 4863, 1951, 13809)
min(x)
## [1] 345
max(x)
## [1] 20310
Problem 1b)
x<-c(2413, 20310, 12637, 2753, 14505, 14440, 2379, 447, 345, 4784, 13803, 12668, 1235, 1257, 1671, 4041, 4145,535, 5270, 3360, 3489, 1979, 2302, 807, 1772, 12807, 5427, 13147, 6288, 1803, 13167, 5343, 6684, 3508, 1549,4975, 11249, 3213, 811, 3560, 7244, 6643, 8571, 13534, 4395, 5729, 14417, 4863, 1951, 13809)
sort(x,decreasing=TRUE)
## [1] 20310 14505 14440 14417 13809 13803 13534 13167 13147 12807 12668 12637
## [13] 11249 8571 7244 6684 6643 6288 5729 5427 5343 5270 4975 4863
## [25] 4784 4395 4145 4041 3560 3508 3489 3360 3213 2753 2413 2379
## [37] 2302 1979 1951 1803 1772 1671 1549 1257 1235 811 807 535
## [49] 447 345
After sorting the values from highest to lowest, Mt. Greylock ranks the 31st highest altitude.
Problem 2a)
y<-seq(from=5,to=-11,by=-0.3)
print(y)
## [1] 5.0 4.7 4.4 4.1 3.8 3.5 3.2 2.9 2.6 2.3 2.0 1.7
## [13] 1.4 1.1 0.8 0.5 0.2 -0.1 -0.4 -0.7 -1.0 -1.3 -1.6 -1.9
## [25] -2.2 -2.5 -2.8 -3.1 -3.4 -3.7 -4.0 -4.3 -4.6 -4.9 -5.2 -5.5
## [37] -5.8 -6.1 -6.4 -6.7 -7.0 -7.3 -7.6 -7.9 -8.2 -8.5 -8.8 -9.1
## [49] -9.4 -9.7 -10.0 -10.3 -10.6 -10.9
Problem 2b and c)
z<-seq(from=-11,to=5,by=0.3)
print(z)
## [1] -11.0 -10.7 -10.4 -10.1 -9.8 -9.5 -9.2 -8.9 -8.6 -8.3 -8.0 -7.7
## [13] -7.4 -7.1 -6.8 -6.5 -6.2 -5.9 -5.6 -5.3 -5.0 -4.7 -4.4 -4.1
## [25] -3.8 -3.5 -3.2 -2.9 -2.6 -2.3 -2.0 -1.7 -1.4 -1.1 -0.8 -0.5
## [37] -0.2 0.1 0.4 0.7 1.0 1.3 1.6 1.9 2.2 2.5 2.8 3.1
## [49] 3.4 3.7 4.0 4.3 4.6 4.9
vector_length<-length(z)
index_vector<-c(1,round(vector_length/2),vector_length)
print(index_vector)
## [1] 1 27 54
Problem 3a and 3b)
b<-c(seq(6,12),rep(5.3,times=3),-3,rep(c(1.2,3.4,5.6),each=2))
print(b)
## [1] 6.0 7.0 8.0 9.0 10.0 11.0 12.0 5.3 5.3 5.3 -3.0 1.2 1.2 3.4 3.4
## [16] 5.6 5.6
vector_length<-length(b)
print(vector_length)
## [1] 17
Problem 4
f<-data.frame(
Name=c("Axel","Jack","Sean","Joe","Hank","Scott","Andy","Matt","Blaze","Damon"),
Age=c(19,18,17,18,21,23,22,21,17,20),
Baseball=c("pitch","3B","2B","1B","SS","Catch","RF","CF","LF","Coach")
)
print(f)
## Name Age Baseball
## 1 Axel 19 pitch
## 2 Jack 18 3B
## 3 Sean 17 2B
## 4 Joe 18 1B
## 5 Hank 21 SS
## 6 Scott 23 Catch
## 7 Andy 22 RF
## 8 Matt 21 CF
## 9 Blaze 17 LF
## 10 Damon 20 Coach
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.