library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.2
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.2
## Warning: package 'stringr' 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 ──
## ✔ forcats 1.0.0 ✔ readr 2.1.4
## ✔ ggplot2 3.4.4 ✔ stringr 1.5.1
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.0
## ── 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)
data("trees")
View(trees)
glimpse(trees)
## Rows: 31
## Columns: 3
## $ Girth <dbl> 8.3, 8.6, 8.8, 10.5, 10.7, 10.8, 11.0, 11.0, 11.1, 11.2, 11.3, …
## $ Height <dbl> 70, 65, 63, 72, 81, 83, 66, 75, 80, 75, 79, 76, 76, 69, 75, 74,…
## $ Volume <dbl> 10.3, 10.3, 10.2, 16.4, 18.8, 19.7, 15.6, 18.2, 22.6, 19.9, 24.…
Trees<-tibble :: as_tibble(trees)
trees%>%summarize(mean=mean(Girth))
## mean
## 1 13.24839
trees%>%summarize(mean=mean(Height))
## mean
## 1 76
trees%>%summarize(mean=mean(Volume))
## mean
## 1 30.17097
trees%>%arrange(-Girth)
## Girth Height Volume
## 1 20.6 87 77.0
## 2 18.0 80 51.5
## 3 18.0 80 51.0
## 4 17.9 80 58.3
## 5 17.5 82 55.7
## 6 17.3 81 55.4
## 7 16.3 77 42.6
## 8 16.0 72 38.3
## 9 14.5 74 36.3
## 10 14.2 80 31.7
## 11 14.0 78 34.5
## 12 13.8 64 24.9
## 13 13.7 71 25.7
## 14 13.3 86 27.4
## 15 12.9 74 22.2
## 16 12.9 85 33.8
## 17 12.0 75 19.1
## 18 11.7 69 21.3
## 19 11.4 76 21.0
## 20 11.4 76 21.4
## 21 11.3 79 24.2
## 22 11.2 75 19.9
## 23 11.1 80 22.6
## 24 11.0 66 15.6
## 25 11.0 75 18.2
## 26 10.8 83 19.7
## 27 10.7 81 18.8
## 28 10.5 72 16.4
## 29 8.8 63 10.2
## 30 8.6 65 10.3
## 31 8.3 70 10.3
trees%>%arrange(-Height)%>%filter(Height>75)
## Girth Height Volume
## 1 20.6 87 77.0
## 2 13.3 86 27.4
## 3 12.9 85 33.8
## 4 10.8 83 19.7
## 5 17.5 82 55.7
## 6 10.7 81 18.8
## 7 17.3 81 55.4
## 8 11.1 80 22.6
## 9 14.2 80 31.7
## 10 17.9 80 58.3
## 11 18.0 80 51.5
## 12 18.0 80 51.0
## 13 11.3 79 24.2
## 14 14.0 78 34.5
## 15 16.3 77 42.6
## 16 11.4 76 21.0
## 17 11.4 76 21.4
trees%>%arrange(-Girth)%>%filter((Volume>25.00)&(Girth>15))
## Girth Height Volume
## 1 20.6 87 77.0
## 2 18.0 80 51.5
## 3 18.0 80 51.0
## 4 17.9 80 58.3
## 5 17.5 82 55.7
## 6 17.3 81 55.4
## 7 16.3 77 42.6
## 8 16.0 72 38.3
trees%>%select(Volume,Height)
## Volume Height
## 1 10.3 70
## 2 10.3 65
## 3 10.2 63
## 4 16.4 72
## 5 18.8 81
## 6 19.7 83
## 7 15.6 66
## 8 18.2 75
## 9 22.6 80
## 10 19.9 75
## 11 24.2 79
## 12 21.0 76
## 13 21.4 76
## 14 21.3 69
## 15 19.1 75
## 16 22.2 74
## 17 33.8 85
## 18 27.4 86
## 19 25.7 71
## 20 24.9 64
## 21 34.5 78
## 22 31.7 80
## 23 36.3 74
## 24 38.3 72
## 25 42.6 77
## 26 55.4 81
## 27 55.7 82
## 28 58.3 80
## 29 51.5 80
## 30 51.0 80
## 31 77.0 87
trees%>%mutate(Treevalue = Girth+Height+Volume)
## Girth Height Volume Treevalue
## 1 8.3 70 10.3 88.6
## 2 8.6 65 10.3 83.9
## 3 8.8 63 10.2 82.0
## 4 10.5 72 16.4 98.9
## 5 10.7 81 18.8 110.5
## 6 10.8 83 19.7 113.5
## 7 11.0 66 15.6 92.6
## 8 11.0 75 18.2 104.2
## 9 11.1 80 22.6 113.7
## 10 11.2 75 19.9 106.1
## 11 11.3 79 24.2 114.5
## 12 11.4 76 21.0 108.4
## 13 11.4 76 21.4 108.8
## 14 11.7 69 21.3 102.0
## 15 12.0 75 19.1 106.1
## 16 12.9 74 22.2 109.1
## 17 12.9 85 33.8 131.7
## 18 13.3 86 27.4 126.7
## 19 13.7 71 25.7 110.4
## 20 13.8 64 24.9 102.7
## 21 14.0 78 34.5 126.5
## 22 14.2 80 31.7 125.9
## 23 14.5 74 36.3 124.8
## 24 16.0 72 38.3 126.3
## 25 16.3 77 42.6 135.9
## 26 17.3 81 55.4 153.7
## 27 17.5 82 55.7 155.2
## 28 17.9 80 58.3 156.2
## 29 18.0 80 51.5 149.5
## 30 18.0 80 51.0 149.0
## 31 20.6 87 77.0 184.6
Values<-trees%>%select(Girth,Height,Volume)%>%mutate(Treevalue = Girth + Height + Volume)
Values%>%arrange(-Treevalue)
## Girth Height Volume Treevalue
## 1 20.6 87 77.0 184.6
## 2 17.9 80 58.3 156.2
## 3 17.5 82 55.7 155.2
## 4 17.3 81 55.4 153.7
## 5 18.0 80 51.5 149.5
## 6 18.0 80 51.0 149.0
## 7 16.3 77 42.6 135.9
## 8 12.9 85 33.8 131.7
## 9 13.3 86 27.4 126.7
## 10 14.0 78 34.5 126.5
## 11 16.0 72 38.3 126.3
## 12 14.2 80 31.7 125.9
## 13 14.5 74 36.3 124.8
## 14 11.3 79 24.2 114.5
## 15 11.1 80 22.6 113.7
## 16 10.8 83 19.7 113.5
## 17 10.7 81 18.8 110.5
## 18 13.7 71 25.7 110.4
## 19 12.9 74 22.2 109.1
## 20 11.4 76 21.4 108.8
## 21 11.4 76 21.0 108.4
## 22 11.2 75 19.9 106.1
## 23 12.0 75 19.1 106.1
## 24 11.0 75 18.2 104.2
## 25 13.8 64 24.9 102.7
## 26 11.7 69 21.3 102.0
## 27 10.5 72 16.4 98.9
## 28 11.0 66 15.6 92.6
## 29 8.3 70 10.3 88.6
## 30 8.6 65 10.3 83.9
## 31 8.8 63 10.2 82.0
Values<-Values%>%select(Treevalue)%>%filter(Treevalue>170)
Values
## Treevalue
## 1 184.6
print("The highest value from 31 Black Cherry Trees is : ")
## [1] "The highest value from 31 Black Cherry Trees is : "
print(Values)
## Treevalue
## 1 184.6