This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
#install.packages(c("tidyverse","multcompView","dplyr","tidyr","ggplot2","readxl"))
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.3 v dplyr 1.0.7
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 2.0.1 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(multcompView)
library(dplyr)
library(tidyr)
library(ggplot2)
library(readxl)
library(datasets)
#cars1<-utils::read.csv("https://github.com/tidyverse/readr/raw/master/inst/extdata/mtcars.csv")
#system.time(accident<-read_csv("https://vincentarelbundock.github.io/Rdatasets/csv/DAAG/nassCDS.csv"))
data("PlantGrowth")
PlantGrowth <- tibble::as_tibble(PlantGrowth)
print(paste('Overall Mean Weighted = ',mean(PlantGrowth$weight)))
## [1] "Overall Mean Weighted = 5.073"
print(paste('Overall Mean Weighted = ',PlantGrowth$weight %>% mean()))
## [1] "Overall Mean Weighted = 5.073"
PlantGrowth %>% group_by(group) %>% summarise(mean=mean(weight), .groups = 'drop')
## # A tibble: 3 x 2
## group mean
## <fct> <dbl>
## 1 ctrl 5.03
## 2 trt1 4.66
## 3 trt2 5.53
PlantGrowth %>% arrange(group,weight)
## # A tibble: 30 x 2
## weight group
## <dbl> <fct>
## 1 4.17 ctrl
## 2 4.5 ctrl
## 3 4.53 ctrl
## 4 4.61 ctrl
## 5 5.14 ctrl
## 6 5.17 ctrl
## 7 5.18 ctrl
## 8 5.33 ctrl
## 9 5.58 ctrl
## 10 6.11 ctrl
## # ... with 20 more rows
PlantGrowth %>% arrange(desc(group,weight))
## # A tibble: 30 x 2
## weight group
## <dbl> <fct>
## 1 6.31 trt2
## 2 5.12 trt2
## 3 5.54 trt2
## 4 5.5 trt2
## 5 5.37 trt2
## 6 5.29 trt2
## 7 4.92 trt2
## 8 6.15 trt2
## 9 5.8 trt2
## 10 5.26 trt2
## # ... with 20 more rows
PlantGrowth %>% filter(group=='ctrl')
## # A tibble: 10 x 2
## weight group
## <dbl> <fct>
## 1 4.17 ctrl
## 2 5.58 ctrl
## 3 5.18 ctrl
## 4 6.11 ctrl
## 5 4.5 ctrl
## 6 4.61 ctrl
## 7 5.17 ctrl
## 8 4.53 ctrl
## 9 5.33 ctrl
## 10 5.14 ctrl
PlantGrowth %>% select(-weight)
## # A tibble: 30 x 1
## group
## <fct>
## 1 ctrl
## 2 ctrl
## 3 ctrl
## 4 ctrl
## 5 ctrl
## 6 ctrl
## 7 ctrl
## 8 ctrl
## 9 ctrl
## 10 ctrl
## # ... with 20 more rows
new_variable = PlantGrowth$weight %>% exp() %>% log() %>% round(1)
PlantGrowth %>% mutate(log_weighted = new_variable)
## # A tibble: 30 x 3
## weight group log_weighted
## <dbl> <fct> <dbl>
## 1 4.17 ctrl 4.2
## 2 5.58 ctrl 5.6
## 3 5.18 ctrl 5.2
## 4 6.11 ctrl 6.1
## 5 4.5 ctrl 4.5
## 6 4.61 ctrl 4.6
## 7 5.17 ctrl 5.2
## 8 4.53 ctrl 4.5
## 9 5.33 ctrl 5.3
## 10 5.14 ctrl 5.1
## # ... with 20 more rows