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:
library(tidyverse)
## -- Attaching packages -------------------------------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.0.0 v purrr 0.2.5
## v tibble 1.4.2 v dplyr 0.7.6
## v tidyr 0.8.1 v stringr 1.3.1
## v readr 1.1.1 v forcats 0.3.0
## -- Conflicts ----------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
mushroomds <- read.csv(url("https://archive.ics.uci.edu/ml/machine-learning-databases/mushroom/agaricus-lepiota.data"), header = FALSE, sep =",")
mushroomds <- mushroomds[c(1,2,3,5)]
head(mushroomds, 20)
## V1 V2 V3 V5
## 1 p x s t
## 2 e x s t
## 3 e b s t
## 4 p x y t
## 5 e x s f
## 6 e x y t
## 7 e b s t
## 8 e b y t
## 9 p x y t
## 10 e b s t
## 11 e x y t
## 12 e x y t
## 13 e b s t
## 14 p x y t
## 15 e x f f
## 16 e s f f
## 17 e f f f
## 18 p x s t
## 19 p x y t
## 20 p x s t
colnames(mushroomds) <- c("Class","Shape","Continent","Soiltype")
levels(mushroomds$`Class`) <- c(levels(mushroomds$`Class`), c("Poisonous","Edible"))
mushroomds$`Class`[mushroomds$`Class` == "p"] <- "Poisonous"
mushroomds$`Class`[mushroomds$`Class` == "e"] <- "Edible"
levels(mushroomds$`Shape`) <- c(levels(mushroomds$`Shape`), c("Bell","Tilted","Curved","Cone","Convex","Flat"))
mushroomds$`Shape`[mushroomds$`Shape` == "b"] <- "Bell"
mushroomds$`Shape`[mushroomds$`Shape` == "c"] <- "Tilted"
mushroomds$`Shape`[mushroomds$`Shape` == "f"] <- "Curved"
mushroomds$`Shape`[mushroomds$`Shape` == "k"] <- "Cone"
mushroomds$`Shape`[mushroomds$`Shape` == "s"] <- "Convex"
mushroomds$`Shape`[mushroomds$`Shape` == "x"] <- "Flat"
levels(mushroomds$`Continent`) <- c(levels(mushroomds$`Continent`), c("Asia", "America","Australia","Europe"))
mushroomds$`Continent`[mushroomds$`Continent` == "s"] <- "Asia"
mushroomds$`Continent`[mushroomds$`Continent` == "y"] <- "America"
mushroomds$`Continent`[mushroomds$`Continent` == "f"] <- "Australia"
mushroomds$`Continent`[mushroomds$`Continent` == "g"] <- "Europe"
levels(mushroomds$`Soiltype`) <- c(levels(mushroomds$`Soiltype`), c("Blacksoil", "Redsoil"))
mushroomds$`Soiltype`[mushroomds$`Soiltype` == "t"] <- "Blacksoil"
mushroomds$`Soiltype`[mushroomds$`Soiltype` == "f"] <- "Redsoil"
head(mushroomds, 10)
## Class Shape Continent Soiltype
## 1 Poisonous Flat Asia Blacksoil
## 2 Edible Flat Asia Blacksoil
## 3 Edible Bell Asia Blacksoil
## 4 Poisonous Flat America Blacksoil
## 5 Edible Flat Asia Redsoil
## 6 Edible Flat America Blacksoil
## 7 Edible Bell Asia Blacksoil
## 8 Edible Bell America Blacksoil
## 9 Poisonous Flat America Blacksoil
## 10 Edible Bell Asia Blacksoil
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.