options(repos = c(CRAN = "https://cran.rstudio.com"))
install.packages("tidyverse")
## package 'tidyverse' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\Ryzen\AppData\Local\Temp\Rtmpiqkn94\downloaded_packages
install.packages("dplyr")
## package 'dplyr' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'dplyr'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## D:\R-4.3.1\library\00LOCK\dplyr\libs\x64\dplyr.dll to
## D:\R-4.3.1\library\dplyr\libs\x64\dplyr.dll: Permission denied
## Warning: restored 'dplyr'
##
## The downloaded binary packages are in
## C:\Users\Ryzen\AppData\Local\Temp\Rtmpiqkn94\downloaded_packages
install.packages("vctrs")
## package 'vctrs' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'vctrs'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## D:\R-4.3.1\library\00LOCK\vctrs\libs\x64\vctrs.dll to
## D:\R-4.3.1\library\vctrs\libs\x64\vctrs.dll: Permission denied
## Warning: restored 'vctrs'
##
## The downloaded binary packages are in
## C:\Users\Ryzen\AppData\Local\Temp\Rtmpiqkn94\downloaded_packages
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.2
## Warning: package 'ggplot2' was built under R version 4.3.2
## Warning: package 'readr' was built under R version 4.3.2
## Warning: package 'dplyr' was built under R version 4.3.2
## Warning: package 'forcats' was built under R version 4.3.2
## Warning: package 'lubridate' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(datasets)
library(vctrs)
## Warning: package 'vctrs' was built under R version 4.3.2
##
## Attaching package: 'vctrs'
##
## The following object is masked from 'package:dplyr':
##
## data_frame
##
## The following object is masked from 'package:tibble':
##
## data_frame
data("quakes")
view(quakes)
quakes <- tibble::as.tibble(quakes)
## Warning: `as.tibble()` was deprecated in tibble 2.0.0.
## ℹ Please use `as_tibble()` instead.
## ℹ The signature and semantics have changed, see `?as_tibble`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
class(quakes)
## [1] "tbl_df" "tbl" "data.frame"
glimpse(quakes)
## Rows: 1,000
## Columns: 5
## $ lat <dbl> -20.42, -20.62, -26.00, -17.97, -20.42, -19.68, -11.70, -28.1…
## $ long <dbl> 181.62, 181.03, 184.10, 181.66, 181.96, 184.31, 166.10, 181.9…
## $ depth <int> 562, 650, 42, 626, 649, 195, 82, 194, 211, 622, 583, 249, 554…
## $ mag <dbl> 4.8, 4.2, 5.4, 4.1, 4.0, 4.0, 4.8, 4.4, 4.7, 4.3, 4.4, 4.6, 4…
## $ stations <int> 41, 15, 43, 19, 11, 12, 43, 15, 35, 19, 13, 16, 19, 10, 94, 1…
head(quakes)
## # A tibble: 6 × 5
## lat long depth mag stations
## <dbl> <dbl> <int> <dbl> <int>
## 1 -20.4 182. 562 4.8 41
## 2 -20.6 181. 650 4.2 15
## 3 -26 184. 42 5.4 43
## 4 -18.0 182. 626 4.1 19
## 5 -20.4 182. 649 4 11
## 6 -19.7 184. 195 4 12
mean(quakes$mag) == quakes$mag %>% mean()
## [1] TRUE
#SUMMARIZE AND ARRANGE
quakes %>% group_by(stations) %>% summarize(mean=mean(mag)) %>% print(n=100)
## # A tibble: 102 × 2
## stations mean
## <int> <dbl>
## 1 10 4.23
## 2 11 4.23
## 3 12 4.20
## 4 13 4.33
## 5 14 4.28
## 6 15 4.28
## 7 16 4.27
## 8 17 4.35
## 9 18 4.44
## 10 19 4.38
## 11 20 4.39
## 12 21 4.36
## 13 22 4.45
## 14 23 4.38
## 15 24 4.48
## 16 25 4.53
## 17 26 4.5
## 18 27 4.58
## 19 28 4.58
## 20 29 4.57
## 21 30 4.65
## 22 31 4.66
## 23 32 4.59
## 24 33 4.59
## 25 34 4.59
## 26 35 4.72
## 27 36 4.69
## 28 37 4.67
## 29 38 4.82
## 30 39 4.63
## 31 40 4.82
## 32 41 4.71
## 33 42 4.78
## 34 43 4.89
## 35 44 4.74
## 36 45 4.97
## 37 46 4.93
## 38 47 4.84
## 39 48 4.93
## 40 49 5.01
## 41 50 4.88
## 42 51 4.85
## 43 52 4.85
## 44 53 5.3
## 45 54 5.05
## 46 55 5
## 47 56 4.98
## 48 57 4.95
## 49 58 5.1
## 50 59 5
## 51 60 5.13
## 52 61 5.2
## 53 62 4.9
## 54 63 5.1
## 55 64 5.08
## 56 65 5.16
## 57 66 5.2
## 58 67 5.24
## 59 68 5.19
## 60 69 5.2
## 61 70 5.23
## 62 71 5.28
## 63 72 5.17
## 64 73 5.3
## 65 74 5.12
## 66 75 5.3
## 67 76 5.7
## 68 77 5
## 69 78 5.35
## 70 79 5.28
## 71 80 5.5
## 72 81 5.3
## 73 82 5.3
## 74 83 6
## 75 85 5.4
## 76 86 5.37
## 77 87 5.4
## 78 88 5.4
## 79 89 5.25
## 80 90 5.7
## 81 91 5.27
## 82 92 5.5
## 83 93 5.3
## 84 94 5.85
## 85 95 5.5
## 86 98 5.6
## 87 99 5.7
## 88 100 5
## 89 104 5.6
## 90 105 5.45
## 91 106 5.7
## 92 109 5.6
## 93 110 5.4
## 94 112 5.7
## 95 115 5.6
## 96 118 5.9
## 97 119 5.95
## 98 121 5.6
## 99 122 6.4
## 100 123 5.7
## # ℹ 2 more rows
quakes %>% arrange(mag) %>% print(n=100)
## # A tibble: 1,000 × 5
## lat long depth mag stations
## <dbl> <dbl> <int> <dbl> <int>
## 1 -20.4 182. 649 4 11
## 2 -19.7 184. 195 4 12
## 3 -17.9 181. 537 4 15
## 4 -23.6 181. 349 4 10
## 5 -19.3 184. 223 4 15
## 6 -22.1 181. 584 4 11
## 7 -15.3 186. 152 4 11
## 8 -17.7 182. 450 4 11
## 9 -19.7 182. 375 4 18
## 10 -19.1 182. 477 4 16
## 11 -20.6 181. 582 4 14
## 12 -17.9 182. 573 4 19
## 13 -17.7 182. 445 4 12
## 14 -23.5 180. 574 4 12
## 15 -17.7 185 383 4 10
## 16 -17.9 182. 601 4 16
## 17 -30.6 181. 175 4 16
## 18 -16.9 186. 135 4 22
## 19 -10.7 166. 195 4 14
## 20 -18.6 182. 563 4 17
## 21 -22.7 183. 180 4 13
## 22 -21 183. 296 4 16
## 23 -17.0 183. 406 4 17
## 24 -19.5 184. 280 4 16
## 25 -15.4 185. 249 4 11
## 26 -17.9 181. 555 4 17
## 27 -17.1 183. 390 4 14
## 28 -30.3 181. 275 4 14
## 29 -25.6 180. 440 4 12
## 30 -20.7 186. 80 4 10
## 31 -16.4 183. 391 4 16
## 32 -21.6 180. 595 4 22
## 33 -17.9 182. 589 4 12
## 34 -28 182 199 4 16
## 35 -22.1 180. 532 4 14
## 36 -21.6 182. 350 4 12
## 37 -19.7 182. 397 4 12
## 38 -18.5 185. 243 4 11
## 39 -21.0 181. 638 4 14
## 40 -17.8 181. 530 4 15
## 41 -17.8 181. 538 4 33
## 42 -25.1 183. 133 4 14
## 43 -18.1 182. 574 4 20
## 44 -23.5 180. 530 4 23
## 45 -17.9 181. 614 4 12
## 46 -18.0 181. 642 4 17
## 47 -18.0 182. 626 4.1 19
## 48 -17.7 181. 585 4.1 17
## 49 -21.2 182. 260 4.1 12
## 50 -20.1 182. 587 4.1 13
## 51 -19.2 185. 197 4.1 11
## 52 -17.0 186. 108 4.1 12
## 53 -18.0 180. 626 4.1 19
## 54 -20.2 181. 627 4.1 11
## 55 -15.2 185. 99 4.1 14
## 56 -15.0 182. 399 4.1 10
## 57 -17.8 181. 542 4.1 20
## 58 -20.4 182. 534 4.1 14
## 59 -24.1 180. 605 4.1 21
## 60 -28.2 182. 226 4.1 19
## 61 -24.4 183. 148 4.1 16
## 62 -23.8 180. 498 4.1 12
## 63 -17.7 181. 515 4.1 19
## 64 -17.3 181. 497 4.1 13
## 65 -17.5 181. 573 4.1 17
## 66 -23.4 183. 158 4.1 20
## 67 -17.0 187. 70 4.1 22
## 68 -18.4 183. 343 4.1 10
## 69 -14.8 185. 294 4.1 10
## 70 -17.9 181. 593 4.1 13
## 71 -17.6 181. 537 4.1 11
## 72 -17.1 185. 223 4.1 15
## 73 -17.8 182. 598 4.1 14
## 74 -19.2 183. 570 4.1 22
## 75 -21.8 185 74 4.1 15
## 76 -17.8 181. 539 4.1 12
## 77 -18.9 181. 655 4.1 14
## 78 -17.6 182. 548 4.1 10
## 79 -17.2 183. 383 4.1 11
## 80 -25.1 178. 554 4.1 15
## 81 -16.4 187. 75 4.1 20
## 82 -17.8 185. 223 4.1 10
## 83 -19.1 185. 230 4.1 16
## 84 -21.8 181 618 4.1 10
## 85 -18.1 182. 593 4.1 16
## 86 -20.2 182. 576 4.1 16
## 87 -19.1 185. 210 4.1 22
## 88 -22.1 180. 603 4.1 11
## 89 -22.1 180. 587 4.1 23
## 90 -15.7 185. 70 4.1 15
## 91 -19.4 182. 326 4.1 15
## 92 -15.8 186. 121 4.1 17
## 93 -17.6 181. 580 4.1 16
## 94 -15.2 186. 77 4.1 16
## 95 -15.6 185. 315 4.1 15
## 96 -17.9 182. 567 4.1 27
## 97 -17.7 181. 559 4.1 16
## 98 -18.4 182. 600 4.1 11
## 99 -23.5 180. 543 4.1 21
## 100 -19.7 184. 223 4.1 23
## # ℹ 900 more rows
quakes %>% arrange(desc(long)) %>% print(n=100)
## # A tibble: 1,000 × 5
## lat long depth mag stations
## <dbl> <dbl> <int> <dbl> <int>
## 1 -15.9 188. 52 5 30
## 2 -17.7 188. 45 4.2 10
## 3 -15.5 188. 40 5.5 91
## 4 -16.5 188. 40 4.5 18
## 5 -17.4 188. 40 4.5 14
## 6 -18.8 188. 44 4.8 35
## 7 -16.1 187. 61 4.5 19
## 8 -16.1 187. 42 5.1 68
## 9 -15.2 187. 50 4.7 28
## 10 -15.6 187. 49 5 30
## 11 -15.5 187. 60 4.5 17
## 12 -16.5 187. 62 4.9 46
## 13 -17.7 187. 45 4.9 62
## 14 -17.0 187 70 4.7 30
## 15 -15.5 187. 46 4.7 18
## 16 -19.5 187. 58 4.4 20
## 17 -15.4 187. 78 4.7 44
## 18 -19.0 187. 45 5.2 65
## 19 -17.7 187. 112 4.5 35
## 20 -17.0 187. 70 4.1 22
## 21 -15.7 187. 45 4.4 11
## 22 -17.7 187. 104 5.1 71
## 23 -15.3 187. 48 5.7 123
## 24 -16.6 187. 82 4.8 51
## 25 -15.5 187. 82 4.4 17
## 26 -15.4 187. 83 4.7 37
## 27 -16.4 187. 75 4.1 20
## 28 -18.8 187. 68 4.8 48
## 29 -15.4 187. 130 5.5 95
## 30 -15.4 187. 112 5.1 57
## 31 -19.3 187. 56 5.2 49
## 32 -17.4 187. 85 4.2 28
## 33 -16.2 187. 111 4.8 30
## 34 -20.4 187. 63 5 28
## 35 -15.4 186. 69 4.3 42
## 36 -15.3 186. 153 4.6 31
## 37 -15.4 186. 98 4.4 17
## 38 -19.4 186. 100 4.7 40
## 39 -15.4 186. 123 4.2 16
## 40 -20.1 186. 63 4.6 19
## 41 -20.7 186. 80 4 10
## 42 -15.6 186. 64 5.1 54
## 43 -15.2 186. 158 5 57
## 44 -19.7 186. 47 4.8 19
## 45 -20.4 186. 102 4.3 21
## 46 -19.3 186. 44 5.4 110
## 47 -15.3 186. 96 4.6 32
## 48 -20.4 186. 74 4.3 22
## 49 -16.0 186. 143 4.6 41
## 50 -15.5 186. 94 4.3 26
## 51 -16.3 186 48 4.5 10
## 52 -15.3 186. 162 4.4 36
## 53 -17.1 186. 180 4.2 29
## 54 -17.0 186. 95 4.3 12
## 55 -15.2 186. 77 4.1 16
## 56 -22.6 186. 42 5.7 76
## 57 -20.8 186. 104 4.5 19
## 58 -17.1 186. 127 5.4 75
## 59 -15.8 186. 121 4.1 17
## 60 -16.4 186. 148 5 47
## 61 -21.5 186. 55 4.9 46
## 62 -19.3 186. 48 5 40
## 63 -15.3 186. 152 4 11
## 64 -21.3 186. 69 4.9 74
## 65 -20.8 186. 118 4.6 15
## 66 -20.7 186. 69 4.3 25
## 67 -21.3 186. 57 5.3 69
## 68 -16.2 186. 154 4.5 22
## 69 -16.4 186. 126 4.7 30
## 70 -17.0 186. 178 4.2 32
## 71 -16.9 186. 135 4 22
## 72 -16.5 186. 90 4.7 30
## 73 -20.5 186. 93 5.4 85
## 74 -15.7 186. 138 4.3 21
## 75 -21.6 186. 66 4.9 38
## 76 -17.0 186. 108 4.1 12
## 77 -19 186. 107 4.5 15
## 78 -21.1 186. 85 5.3 86
## 79 -16.6 186. 218 5 52
## 80 -22 186. 52 4.4 18
## 81 -21.6 186. 47 4.5 29
## 82 -21.5 185. 51 5 29
## 83 -18 185. 143 4.4 29
## 84 -17.4 185. 189 4.5 22
## 85 -16.0 185. 297 4.8 25
## 86 -18.5 185. 243 4 11
## 87 -19.6 185. 57 4.9 31
## 88 -17.8 185. 223 4.1 10
## 89 -21.1 185. 123 4.7 36
## 90 -16.1 185. 257 4.7 30
## 91 -17.1 185. 223 4.1 15
## 92 -15.9 185. 57 4.4 19
## 93 -22.1 185. 50 4.6 22
## 94 -15.5 185. 93 4.4 25
## 95 -18.4 185. 201 4.7 57
## 96 -15.4 185. 224 4.2 21
## 97 -20.9 185. 54 5.1 44
## 98 -19.0 185. 129 5.1 73
## 99 -15.8 185. 82 4.4 39
## 100 -15.8 185. 280 4.5 28
## # ℹ 900 more rows
#SUMMARIZE AND ARRANGE
quakes %>% group_by(stations) %>% summarize(mean=mean(mag))
## # A tibble: 102 × 2
## stations mean
## <int> <dbl>
## 1 10 4.23
## 2 11 4.23
## 3 12 4.20
## 4 13 4.33
## 5 14 4.28
## 6 15 4.28
## 7 16 4.27
## 8 17 4.35
## 9 18 4.44
## 10 19 4.38
## # ℹ 92 more rows
quakes %>% arrange(mag)
## # A tibble: 1,000 × 5
## lat long depth mag stations
## <dbl> <dbl> <int> <dbl> <int>
## 1 -20.4 182. 649 4 11
## 2 -19.7 184. 195 4 12
## 3 -17.9 181. 537 4 15
## 4 -23.6 181. 349 4 10
## 5 -19.3 184. 223 4 15
## 6 -22.1 181. 584 4 11
## 7 -15.3 186. 152 4 11
## 8 -17.7 182. 450 4 11
## 9 -19.7 182. 375 4 18
## 10 -19.1 182. 477 4 16
## # ℹ 990 more rows
quakes %>% arrange(desc(mag))
## # A tibble: 1,000 × 5
## lat long depth mag stations
## <dbl> <dbl> <int> <dbl> <int>
## 1 -15.6 168. 127 6.4 122
## 2 -20.7 170. 139 6.1 94
## 3 -13.6 166. 50 6 83
## 4 -12.2 167. 242 6 132
## 5 -21.6 171. 165 6 119
## 6 -22.9 184. 64 5.9 118
## 7 -21.1 181. 627 5.9 119
## 8 -22.6 186. 42 5.7 76
## 9 -23.3 184. 56 5.7 106
## 10 -32.2 180. 216 5.7 90
## # ℹ 990 more rows
#SELECT AND FILTER
quakes %>% filter(stations=="14") %>% print(n=30)
## # A tibble: 39 × 5
## lat long depth mag stations
## <dbl> <dbl> <int> <dbl> <int>
## 1 -11.6 166. 96 4.3 14
## 2 -19.7 170. 271 4.2 14
## 3 -16.8 182. 388 4.2 14
## 4 -13.5 172. 64 4.7 14
## 5 -21.3 181. 624 4.3 14
## 6 -24.0 183. 199 4.6 14
## 7 -20.6 181. 582 4 14
## 8 -11.8 166. 69 4.2 14
## 9 -15.2 185. 99 4.1 14
## 10 -20.4 182. 534 4.1 14
## 11 -24 183. 175 4.5 14
## 12 -20.3 182. 508 4.5 14
## 13 -18.3 182. 342 4.2 14
## 14 -18.7 169. 82 4.4 14
## 15 -17.4 181. 479 4.4 14
## 16 -29.5 182. 129 4.4 14
## 17 -27.2 182. 56 4.5 14
## 18 -27.2 182. 65 4.2 14
## 19 -27.2 182. 69 4.3 14
## 20 -18.0 182. 590 4.2 14
## 21 -18.3 183. 103 4.5 14
## 22 -18.2 182. 553 4.4 14
## 23 -17.8 181. 573 4.2 14
## 24 -10.7 166. 195 4 14
## 25 -17.5 182. 417 4.2 14
## 26 -27.6 183. 80 4.3 14
## 27 -19.8 183. 524 4.6 14
## 28 -17.8 182. 598 4.1 14
## 29 -18.9 181. 655 4.1 14
## 30 -17.1 183. 390 4 14
## # ℹ 9 more rows
quakes %>% select(long,depth,mag,) %>% print(n=100)
## # A tibble: 1,000 × 3
## long depth mag
## <dbl> <int> <dbl>
## 1 182. 562 4.8
## 2 181. 650 4.2
## 3 184. 42 5.4
## 4 182. 626 4.1
## 5 182. 649 4
## 6 184. 195 4
## 7 166. 82 4.8
## 8 182. 194 4.4
## 9 182. 211 4.7
## 10 180. 622 4.3
## 11 181. 583 4.4
## 12 167 249 4.6
## 13 182. 554 4.4
## 14 182. 600 4.4
## 15 170. 139 6.1
## 16 185. 306 4.3
## 17 166. 50 6
## 18 182. 590 4.5
## 19 180. 570 4.4
## 20 180. 598 4.4
## 21 181. 576 4.5
## 22 166. 211 4.2
## 23 180. 512 4.4
## 24 182 125 4.7
## 25 180. 431 5.4
## 26 181. 537 4
## 27 168. 155 4.6
## 28 181. 498 5.2
## 29 181. 582 4.5
## 30 182. 328 4.4
## 31 179. 553 4.6
## 32 167. 50 4.7
## 33 185. 292 4.8
## 34 181. 349 4
## 35 186 48 4.5
## 36 179. 600 4.3
## 37 169. 206 4.5
## 38 181. 574 4.6
## 39 181. 585 4.1
## 40 169. 230 4.4
## 41 177. 263 4.7
## 42 186. 96 4.6
## 43 180. 511 4.4
## 44 186. 94 4.3
## 45 169. 246 4.6
## 46 182. 56 4.9
## 47 182. 329 4.5
## 48 166. 70 4.4
## 49 180. 493 4.3
## 50 185. 129 5.1
## 51 182. 554 4.2
## 52 184. 223 4
## 53 173. 46 4.6
## 54 181. 593 4.3
## 55 182. 489 4.2
## 56 182. 562 4.4
## 57 181 445 4.5
## 58 181. 584 4
## 59 181. 535 4.4
## 60 179. 530 4.3
## 61 182. 582 4.7
## 62 182. 260 4.1
## 63 172. 613 5
## 64 166. 84 4.6
## 65 181. 593 4.9
## 66 185. 286 4.7
## 67 182. 587 4.1
## 68 180. 627 5
## 69 182. 530 4.5
## 70 188. 40 5.5
## 71 186. 152 4
## 72 184. 201 4.5
## 73 166. 96 4.3
## 74 180. 506 5.2
## 75 181. 546 4.4
## 76 180. 564 4.3
## 77 185. 197 4.1
## 78 167. 265 4.5
## 79 182. 323 4.2
## 80 181. 304 5.3
## 81 180. 75 5.2
## 82 181. 367 4.5
## 83 182. 579 4.6
## 84 183. 284 4.3
## 85 182. 450 4
## 86 184. 170 4.3
## 87 170. 117 4.7
## 88 180. 538 4.5
## 89 186. 123 4.2
## 90 186. 69 4.3
## 91 168. 128 5.1
## 92 167. 236 4.7
## 93 182. 497 5.2
## 94 170. 271 4.2
## 95 185. 224 4.2
## 96 182. 375 4
## 97 181. 365 4.5
## 98 183. 306 5.2
## 99 167. 50 5.1
## 100 180. 484 4.7
## # ℹ 900 more rows
quakes %>% select(-stations) %>% print(n=100)
## # A tibble: 1,000 × 4
## lat long depth mag
## <dbl> <dbl> <int> <dbl>
## 1 -20.4 182. 562 4.8
## 2 -20.6 181. 650 4.2
## 3 -26 184. 42 5.4
## 4 -18.0 182. 626 4.1
## 5 -20.4 182. 649 4
## 6 -19.7 184. 195 4
## 7 -11.7 166. 82 4.8
## 8 -28.1 182. 194 4.4
## 9 -28.7 182. 211 4.7
## 10 -17.5 180. 622 4.3
## 11 -21.4 181. 583 4.4
## 12 -12.3 167 249 4.6
## 13 -18.5 182. 554 4.4
## 14 -21 182. 600 4.4
## 15 -20.7 170. 139 6.1
## 16 -15.9 185. 306 4.3
## 17 -13.6 166. 50 6
## 18 -17.8 182. 590 4.5
## 19 -23.5 180. 570 4.4
## 20 -22.6 180. 598 4.4
## 21 -20.8 181. 576 4.5
## 22 -11.0 166. 211 4.2
## 23 -23.3 180. 512 4.4
## 24 -30.2 182 125 4.7
## 25 -19.7 180. 431 5.4
## 26 -17.9 181. 537 4
## 27 -14.7 168. 155 4.6
## 28 -16.5 181. 498 5.2
## 29 -21.0 181. 582 4.5
## 30 -19.8 182. 328 4.4
## 31 -22.6 179. 553 4.6
## 32 -16.3 167. 50 4.7
## 33 -15.6 185. 292 4.8
## 34 -23.6 181. 349 4
## 35 -16.3 186 48 4.5
## 36 -25.8 179. 600 4.3
## 37 -18.7 169. 206 4.5
## 38 -17.6 181. 574 4.6
## 39 -17.7 181. 585 4.1
## 40 -18.8 169. 230 4.4
## 41 -37.4 177. 263 4.7
## 42 -15.3 186. 96 4.6
## 43 -25.0 180. 511 4.4
## 44 -15.5 186. 94 4.3
## 45 -19.2 169. 246 4.6
## 46 -30.1 182. 56 4.9
## 47 -26.4 182. 329 4.5
## 48 -11.8 166. 70 4.4
## 49 -24.1 180. 493 4.3
## 50 -19.0 185. 129 5.1
## 51 -18.8 182. 554 4.2
## 52 -19.3 184. 223 4
## 53 -22.8 173. 46 4.6
## 54 -21.4 181. 593 4.3
## 55 -20.1 182. 489 4.2
## 56 -19.8 182. 562 4.4
## 57 -22.7 181 445 4.5
## 58 -22.1 181. 584 4
## 59 -17.8 181. 535 4.4
## 60 -24.2 179. 530 4.3
## 61 -20.7 182. 582 4.7
## 62 -21.2 182. 260 4.1
## 63 -13.8 172. 613 5
## 64 -11.5 166. 84 4.6
## 65 -20.7 181. 593 4.9
## 66 -17.1 185. 286 4.7
## 67 -20.1 182. 587 4.1
## 68 -22.0 180. 627 5
## 69 -20.4 182. 530 4.5
## 70 -15.5 188. 40 5.5
## 71 -15.3 186. 152 4
## 72 -19.9 184. 201 4.5
## 73 -11.6 166. 96 4.3
## 74 -23.7 180. 506 5.2
## 75 -17.7 181. 546 4.4
## 76 -23.5 180. 564 4.3
## 77 -19.2 185. 197 4.1
## 78 -12.1 167. 265 4.5
## 79 -21.8 182. 323 4.2
## 80 -29.0 181. 304 5.3
## 81 -34.0 180. 75 5.2
## 82 -23.8 181. 367 4.5
## 83 -19.6 182. 579 4.6
## 84 -20.1 183. 284 4.3
## 85 -17.7 182. 450 4
## 86 -19.7 184. 170 4.3
## 87 -21.5 170. 117 4.7
## 88 -23.6 180. 538 4.5
## 89 -15.4 186. 123 4.2
## 90 -15.4 186. 69 4.3
## 91 -15.5 168. 128 5.1
## 92 -13.4 167. 236 4.7
## 93 -20.6 182. 497 5.2
## 94 -19.7 170. 271 4.2
## 95 -15.4 185. 224 4.2
## 96 -19.7 182. 375 4
## 97 -27.2 181. 365 4.5
## 98 -18.2 183. 306 5.2
## 99 -13.7 167. 50 5.1
## 100 -24.6 180. 484 4.7
## # ℹ 900 more rows
#SELECT AND FILTER
quakes %>% filter(mag=="4.4")
## # A tibble: 101 × 5
## lat long depth mag stations
## <dbl> <dbl> <int> <dbl> <int>
## 1 -28.1 182. 194 4.4 15
## 2 -21.4 181. 583 4.4 13
## 3 -18.5 182. 554 4.4 19
## 4 -21 182. 600 4.4 10
## 5 -23.5 180. 570 4.4 13
## 6 -22.6 180. 598 4.4 18
## 7 -23.3 180. 512 4.4 18
## 8 -19.8 182. 328 4.4 17
## 9 -18.8 169. 230 4.4 11
## 10 -25.0 180. 511 4.4 23
## # ℹ 91 more rows
quakes %>% select(lat,long,depth)
## # A tibble: 1,000 × 3
## lat long depth
## <dbl> <dbl> <int>
## 1 -20.4 182. 562
## 2 -20.6 181. 650
## 3 -26 184. 42
## 4 -18.0 182. 626
## 5 -20.4 182. 649
## 6 -19.7 184. 195
## 7 -11.7 166. 82
## 8 -28.1 182. 194
## 9 -28.7 182. 211
## 10 -17.5 180. 622
## # ℹ 990 more rows
quakes %>% select(-lat,-long)
## # A tibble: 1,000 × 3
## depth mag stations
## <int> <dbl> <int>
## 1 562 4.8 41
## 2 650 4.2 15
## 3 42 5.4 43
## 4 626 4.1 19
## 5 649 4 11
## 6 195 4 12
## 7 82 4.8 43
## 8 194 4.4 15
## 9 211 4.7 35
## 10 622 4.3 19
## # ℹ 990 more rows
#MUTATE
quakes %>% mutate(area=3.14*long*long)
## # A tibble: 1,000 × 6
## lat long depth mag stations area
## <dbl> <dbl> <int> <dbl> <int> <dbl>
## 1 -20.4 182. 562 4.8 41 103575.
## 2 -20.6 181. 650 4.2 15 102904.
## 3 -26 184. 42 5.4 43 106423.
## 4 -18.0 182. 626 4.1 19 103621.
## 5 -20.4 182. 649 4 11 103964.
## 6 -19.7 184. 195 4 12 106666.
## 7 -11.7 166. 82 4.8 43 86630.
## 8 -28.1 182. 194 4.4 15 103929.
## 9 -28.7 182. 211 4.7 35 103712.
## 10 -17.5 180. 622 4.3 19 101273.
## # ℹ 990 more rows
new_quakes <- quakes %>% select(-stations,-lat) %>% mutate(area=3.14*long*long)
new_quakes %>% print(n=102)
## # A tibble: 1,000 × 4
## long depth mag area
## <dbl> <int> <dbl> <dbl>
## 1 182. 562 4.8 103575.
## 2 181. 650 4.2 102904.
## 3 184. 42 5.4 106423.
## 4 182. 626 4.1 103621.
## 5 182. 649 4 103964.
## 6 184. 195 4 106666.
## 7 166. 82 4.8 86630.
## 8 182. 194 4.4 103929.
## 9 182. 211 4.7 103712.
## 10 180. 622 4.3 101273.
## 11 181. 583 4.4 102517.
## 12 167 249 4.6 87571.
## 13 182. 554 4.4 104135.
## 14 182. 600 4.4 103621.
## 15 170. 139 6.1 90661.
## 16 185. 306 4.3 107408.
## 17 166. 50 6 86484.
## 18 182. 590 4.5 103439.
## 19 180. 570 4.4 101487.
## 20 180. 598 4.4 102087.
## 21 181. 576 4.5 103051.
## 22 166. 211 4.2 86860.
## 23 180. 512 4.4 101917.
## 24 182 125 4.7 104009.
## 25 180. 431 5.4 102053.
## 26 181. 537 4 103427.
## 27 168. 155 4.6 88107.
## 28 181. 498 5.2 102631.
## 29 181. 582 4.5 103404.
## 30 182. 328 4.4 104433.
## 31 179. 553 4.6 100879.
## 32 167. 50 4.7 87299.
## 33 185. 292 4.8 107525.
## 34 181. 349 4 102642.
## 35 186 48 4.5 108631.
## 36 179. 600 4.3 100980.
## 37 169. 206 4.5 89926.
## 38 181. 574 4.6 103188.
## 39 181. 585 4.1 103325.
## 40 169. 230 4.4 90032.
## 41 177. 263 4.7 98129.
## 42 186. 96 4.6 108748.
## 43 180. 511 4.4 101533.
## 44 186. 94 4.3 108678.
## 45 169. 246 4.6 90117.
## 46 182. 56 4.9 104353.
## 47 182. 329 4.5 103667.
## 48 166. 70 4.4 86860.
## 49 180. 493 4.3 101826.
## 50 185. 129 5.1 107757.
## 51 182. 554 4.2 104410.
## 52 184. 223 4 106794.
## 53 173. 46 4.6 94194.
## 54 181. 593 4.3 102495.
## 55 182. 489 4.2 104192.
## 56 182. 562 4.4 104158.
## 57 181 445 4.5 102870.
## 58 181. 584 4 102415.
## 59 181. 535 4.4 103268.
## 60 179. 530 4.3 100834.
## 61 182. 582 4.7 103496.
## 62 182. 260 4.1 104467.
## 63 172. 613 5 93305.
## 64 166. 84 4.6 86755.
## 65 181. 593 4.9 103336.
## 66 185. 286 4.7 107385.
## 67 182. 587 4.1 103553.
## 68 180. 627 5 101307.
## 69 182. 530 4.5 103849.
## 70 188. 40 5.5 110756.
## 71 186. 152 4 108398.
## 72 184. 201 4.5 106713.
## 73 166. 96 4.3 86734.
## 74 180. 506 5.2 101725.
## 75 181. 546 4.4 103131.
## 76 180. 564 4.3 101781.
## 77 185. 197 4.1 107118.
## 78 167. 265 4.5 87634.
## 79 182. 323 4.2 103678.
## 80 181. 304 5.3 102995.
## 81 180. 75 5.2 101974.
## 82 181. 367 4.5 102858.
## 83 182. 579 4.6 104444.
## 84 183. 284 4.3 105616.
## 85 182. 450 4 103667.
## 86 184. 170 4.3 106666.
## 87 170. 117 4.7 91281.
## 88 180. 538 4.5 101691.
## 89 186. 123 4.2 108982.
## 90 186. 69 4.3 109146.
## 91 168. 128 5.1 88128.
## 92 167. 236 4.7 87634.
## 93 182. 497 5.2 104032.
## 94 170. 271 4.2 90437.
## 95 185. 224 4.2 107769.
## 96 182. 375 4 104467.
## 97 181. 365 4.5 102995.
## 98 183. 306 5.2 105627.
## 99 167. 50 5.1 87090.
## 100 180. 484 4.7 101646.
## 101 186. 108 4.1 108176.
## 102 178. 583 4.6 99947.
## # ℹ 898 more rows
#MUTATE
quakes %>% mutate(longlat=long+lat)
## # A tibble: 1,000 × 6
## lat long depth mag stations longlat
## <dbl> <dbl> <int> <dbl> <int> <dbl>
## 1 -20.4 182. 562 4.8 41 161.
## 2 -20.6 181. 650 4.2 15 160.
## 3 -26 184. 42 5.4 43 158.
## 4 -18.0 182. 626 4.1 19 164.
## 5 -20.4 182. 649 4 11 162.
## 6 -19.7 184. 195 4 12 165.
## 7 -11.7 166. 82 4.8 43 154.
## 8 -28.1 182. 194 4.4 15 154.
## 9 -28.7 182. 211 4.7 35 153
## 10 -17.5 180. 622 4.3 19 162.
## # ℹ 990 more rows
quakesbaru <- quakes %>% select(-lat,-long) %>% mutate(jumlah=mag+stations)
quakesbaru
## # A tibble: 1,000 × 4
## depth mag stations jumlah
## <int> <dbl> <int> <dbl>
## 1 562 4.8 41 45.8
## 2 650 4.2 15 19.2
## 3 42 5.4 43 48.4
## 4 626 4.1 19 23.1
## 5 649 4 11 15
## 6 195 4 12 16
## 7 82 4.8 43 47.8
## 8 194 4.4 15 19.4
## 9 211 4.7 35 39.7
## 10 622 4.3 19 23.3
## # ℹ 990 more rows