1. Read Mushrooms data from the webpage.
mushrooms_data<-read.csv('https://archive.ics.uci.edu/ml/machine-learning-databases/mushroom/agaricus-lepiota.data')
head(mushrooms_data)
##   p x s n t p.1 f c n.1 k e e.1 s.1 s.2 w w.1 p.2 w.2 o p.3 k.1 s.3 u
## 1 e x s y t   a f c   b k e   c   s   s w   w   p   w o   p   n   n g
## 2 e b s w t   l f c   b n e   c   s   s w   w   p   w o   p   n   n m
## 3 p x y w t   p f c   n n e   e   s   s w   w   p   w o   p   k   s u
## 4 e x s g f   n f w   b k t   e   s   s w   w   p   w o   e   n   a g
## 5 e x y y t   a f c   b n e   c   s   s w   w   p   w o   p   k   n g
## 6 e b s w t   a f c   b g e   c   s   s w   w   p   w o   p   k   n m
  1. Create mushrooms data subset that includes mushroom class column and four other columns.
mushrooms_set<-mushrooms_data[c(1,2,11,18,23)]
head(mushrooms_set)
##   p x e w.2 u
## 1 e x e   w g
## 2 e b e   w m
## 3 p x e   w u
## 4 e x t   w g
## 5 e x e   w g
## 6 e b e   w m
  1. Create meaningful names for mushrooms data subset.
names(mushrooms_set)<-c("Mushroom_class","Cape_Shape","Stalk_Shape","Veil_Color","Habitat")
names(mushrooms_set)
## [1] "Mushroom_class" "Cape_Shape"     "Stalk_Shape"    "Veil_Color"    
## [5] "Habitat"
  1. Display factors levels.
levels(mushrooms_set$Mushroom_class)
## [1] "e" "p"
levels(mushrooms_set$Cape_Shape)
## [1] "b" "c" "f" "k" "s" "x"
levels(mushrooms_set$Stalk_Shape)
## [1] "e" "t"
levels(mushrooms_set$Veil_Color)
## [1] "n" "o" "w" "y"
levels(mushrooms_set$Habitat)
## [1] "d" "g" "l" "m" "p" "u" "w"
  1. Replace existinf factor levels with meaningful values.
levels(mushrooms_set$Mushroom_class)<-list(edible="e",poisonous="p")
levels(mushrooms_set$Cape_Shape)<-list(bell="b",conical="c",convex="x",flat="f", knobbed="k",sunken="s")
levels(mushrooms_set$Stalk_Shape)<-list(enlarging="e",tapering="t")
levels(mushrooms_set$Veil_Color)<-list(brown="n",orange="o",white="w",yellow="y")
levels(mushrooms_set$Habitat)<-list(grasses="g",leaves="l",meadows="m",paths="p", urban="u",waste="w",woods="d")
  1. Display modified factors levels.
levels(mushrooms_set$Mushroom_class)
## [1] "edible"    "poisonous"
levels(mushrooms_set$Cape_Shape)
## [1] "bell"    "conical" "convex"  "flat"    "knobbed" "sunken"
levels(mushrooms_set$Stalk_Shape)
## [1] "enlarging" "tapering"
levels(mushrooms_set$Veil_Color)
## [1] "brown"  "orange" "white"  "yellow"
levels(mushrooms_set$Habitat)
## [1] "grasses" "leaves"  "meadows" "paths"   "urban"   "waste"   "woods"
  1. Display modified mushrooms data subset.
head(mushrooms_set)
##   Mushroom_class Cape_Shape Stalk_Shape Veil_Color Habitat
## 1         edible     convex   enlarging      white grasses
## 2         edible       bell   enlarging      white meadows
## 3      poisonous     convex   enlarging      white   urban
## 4         edible     convex    tapering      white grasses
## 5         edible     convex   enlarging      white grasses
## 6         edible       bell   enlarging      white meadows