setwd = "E:\\Box Sync\\Box Sync\\CUNY\\Summer Bridge 2017\\Week2 - R"
Summary to gain overview of the dataset. Display mean and median for two attributes.
summary(quakes)
## lat long depth mag
## Min. :-38.59 Min. :165.7 Min. : 40.0 Min. :4.00
## 1st Qu.:-23.47 1st Qu.:179.6 1st Qu.: 99.0 1st Qu.:4.30
## Median :-20.30 Median :181.4 Median :247.0 Median :4.60
## Mean :-20.64 Mean :179.5 Mean :311.4 Mean :4.62
## 3rd Qu.:-17.64 3rd Qu.:183.2 3rd Qu.:543.0 3rd Qu.:4.90
## Max. :-10.72 Max. :188.1 Max. :680.0 Max. :6.40
## stations
## Min. : 10.00
## 1st Qu.: 18.00
## Median : 27.00
## Mean : 33.42
## 3rd Qu.: 42.00
## Max. :132.00
mean(quakes$depth)
## [1] 311.371
mean(quakes$mag)
## [1] 4.6204
median(quakes$depth)
## [1] 247
median(quakes$mag)
## [1] 4.6
Create a new data frame with a subset of the columns and rows. Make sure to rename it.
quakes_subset = subset(quakes, depth > mean(quakes$depth), select = c(depth,mag))
Create new column names for the new data frame
colnames(quakes_subset) <- c("depth_above_average", "magnitude")
Use the summary function to create an overview of your new data frame. The print the mean and median for the same two attributes. Please compare.
Comparions: Mean and median of the depth of the subset is much higher at 535 and 554 compared to 311,247 in the original dataset. More interstinginly, mean and median of magntiude of the subet is both 4.5 compared to both 4.6 in the original dataset. Seems like higher depth doesn’t necessarily result in higher magnitude.
summary(quakes_subset)
## depth_above_average magnitude
## Min. :315.0 Min. :4.000
## 1st Qu.:498.0 1st Qu.:4.200
## Median :554.0 Median :4.500
## Mean :535.6 Mean :4.525
## 3rd Qu.:594.0 3rd Qu.:4.700
## Max. :680.0 Max. :5.900
print(mean(quakes_subset$depth_above_average))
## [1] 535.5833
print(mean(quakes_subset$magnitude))
## [1] 4.525225
print(median(quakes_subset$depth_above_average))
## [1] 554
print(median(quakes_subset$magnitude))
## [1] 4.5
For at least 3 values in a column please rename so that every value in that column is renamed. For example, suppose I have 20 values of the letter “e” in one column. Rename those values so that all 20 would show as “excellent”
Changing if magnitudes is greater than 4.9, change to 6
quakes_subset_replace = quakes_subset
quakes_subset_replace[quakes_subset_replace$magnitude > 4.9, "magnitude"] <- 6
Display enough rows to see examples of all of steps 1-5 above.
print(quakes[1:67,])
## lat long depth mag stations
## 1 -20.42 181.62 562 4.8 41
## 2 -20.62 181.03 650 4.2 15
## 3 -26.00 184.10 42 5.4 43
## 4 -17.97 181.66 626 4.1 19
## 5 -20.42 181.96 649 4.0 11
## 6 -19.68 184.31 195 4.0 12
## 7 -11.70 166.10 82 4.8 43
## 8 -28.11 181.93 194 4.4 15
## 9 -28.74 181.74 211 4.7 35
## 10 -17.47 179.59 622 4.3 19
## 11 -21.44 180.69 583 4.4 13
## 12 -12.26 167.00 249 4.6 16
## 13 -18.54 182.11 554 4.4 19
## 14 -21.00 181.66 600 4.4 10
## 15 -20.70 169.92 139 6.1 94
## 16 -15.94 184.95 306 4.3 11
## 17 -13.64 165.96 50 6.0 83
## 18 -17.83 181.50 590 4.5 21
## 19 -23.50 179.78 570 4.4 13
## 20 -22.63 180.31 598 4.4 18
## 21 -20.84 181.16 576 4.5 17
## 22 -10.98 166.32 211 4.2 12
## 23 -23.30 180.16 512 4.4 18
## 24 -30.20 182.00 125 4.7 22
## 25 -19.66 180.28 431 5.4 57
## 26 -17.94 181.49 537 4.0 15
## 27 -14.72 167.51 155 4.6 18
## 28 -16.46 180.79 498 5.2 79
## 29 -20.97 181.47 582 4.5 25
## 30 -19.84 182.37 328 4.4 17
## 31 -22.58 179.24 553 4.6 21
## 32 -16.32 166.74 50 4.7 30
## 33 -15.55 185.05 292 4.8 42
## 34 -23.55 180.80 349 4.0 10
## 35 -16.30 186.00 48 4.5 10
## 36 -25.82 179.33 600 4.3 13
## 37 -18.73 169.23 206 4.5 17
## 38 -17.64 181.28 574 4.6 17
## 39 -17.66 181.40 585 4.1 17
## 40 -18.82 169.33 230 4.4 11
## 41 -37.37 176.78 263 4.7 34
## 42 -15.31 186.10 96 4.6 32
## 43 -24.97 179.82 511 4.4 23
## 44 -15.49 186.04 94 4.3 26
## 45 -19.23 169.41 246 4.6 27
## 46 -30.10 182.30 56 4.9 34
## 47 -26.40 181.70 329 4.5 24
## 48 -11.77 166.32 70 4.4 18
## 49 -24.12 180.08 493 4.3 21
## 50 -18.97 185.25 129 5.1 73
## 51 -18.75 182.35 554 4.2 13
## 52 -19.26 184.42 223 4.0 15
## 53 -22.75 173.20 46 4.6 26
## 54 -21.37 180.67 593 4.3 13
## 55 -20.10 182.16 489 4.2 16
## 56 -19.85 182.13 562 4.4 31
## 57 -22.70 181.00 445 4.5 17
## 58 -22.06 180.60 584 4.0 11
## 59 -17.80 181.35 535 4.4 23
## 60 -24.20 179.20 530 4.3 12
## 61 -20.69 181.55 582 4.7 35
## 62 -21.16 182.40 260 4.1 12
## 63 -13.82 172.38 613 5.0 61
## 64 -11.49 166.22 84 4.6 32
## 65 -20.68 181.41 593 4.9 40
## 66 -17.10 184.93 286 4.7 25
## 67 -20.14 181.60 587 4.1 13
print(quakes_subset[1:67,])
## depth_above_average magnitude
## 1 562 4.8
## 2 650 4.2
## 4 626 4.1
## 5 649 4.0
## 10 622 4.3
## 11 583 4.4
## 13 554 4.4
## 14 600 4.4
## 18 590 4.5
## 19 570 4.4
## 20 598 4.4
## 21 576 4.5
## 23 512 4.4
## 25 431 5.4
## 26 537 4.0
## 28 498 5.2
## 29 582 4.5
## 30 328 4.4
## 31 553 4.6
## 34 349 4.0
## 36 600 4.3
## 38 574 4.6
## 39 585 4.1
## 43 511 4.4
## 47 329 4.5
## 49 493 4.3
## 51 554 4.2
## 54 593 4.3
## 55 489 4.2
## 56 562 4.4
## 57 445 4.5
## 58 584 4.0
## 59 535 4.4
## 60 530 4.3
## 61 582 4.7
## 63 613 5.0
## 65 593 4.9
## 67 587 4.1
## 68 627 5.0
## 69 530 4.5
## 74 506 5.2
## 75 546 4.4
## 76 564 4.3
## 79 323 4.2
## 82 367 4.5
## 83 579 4.6
## 85 450 4.0
## 88 538 4.5
## 93 497 5.2
## 96 375 4.0
## 97 365 4.5
## 100 484 4.7
## 102 583 4.6
## 103 608 4.7
## 105 636 4.6
## 112 388 4.2
## 113 477 4.0
## 114 617 4.8
## 115 606 4.4
## 116 609 4.2
## 123 606 4.7
## 124 571 4.5
## 125 328 4.4
## 127 517 4.2
## 128 600 5.0
## 132 527 4.2
## 134 510 4.6
print(quakes_subset_replace[1:67,])
## depth_above_average magnitude
## 1 562 4.8
## 2 650 4.2
## 4 626 4.1
## 5 649 4.0
## 10 622 4.3
## 11 583 4.4
## 13 554 4.4
## 14 600 4.4
## 18 590 4.5
## 19 570 4.4
## 20 598 4.4
## 21 576 4.5
## 23 512 4.4
## 25 431 6.0
## 26 537 4.0
## 28 498 6.0
## 29 582 4.5
## 30 328 4.4
## 31 553 4.6
## 34 349 4.0
## 36 600 4.3
## 38 574 4.6
## 39 585 4.1
## 43 511 4.4
## 47 329 4.5
## 49 493 4.3
## 51 554 4.2
## 54 593 4.3
## 55 489 4.2
## 56 562 4.4
## 57 445 4.5
## 58 584 4.0
## 59 535 4.4
## 60 530 4.3
## 61 582 4.7
## 63 613 6.0
## 65 593 4.9
## 67 587 4.1
## 68 627 6.0
## 69 530 4.5
## 74 506 6.0
## 75 546 4.4
## 76 564 4.3
## 79 323 4.2
## 82 367 4.5
## 83 579 4.6
## 85 450 4.0
## 88 538 4.5
## 93 497 6.0
## 96 375 4.0
## 97 365 4.5
## 100 484 4.7
## 102 583 4.6
## 103 608 4.7
## 105 636 4.6
## 112 388 4.2
## 113 477 4.0
## 114 617 4.8
## 115 606 4.4
## 116 609 4.2
## 123 606 4.7
## 124 571 4.5
## 125 328 4.4
## 127 517 4.2
## 128 600 6.0
## 132 527 4.2
## 134 510 4.6
Read in R from github
require(RCurl)
## Loading required package: RCurl
## Loading required package: bitops
quakes_temp <-read.csv(text=getURL("https://raw.githubusercontent.com/milkcake81/CUNYSummer2017/R-Assignments/quakes.csv"))