library(XML)
## Warning: package 'XML' was built under R version 3.2.5
mushroomurl = "https://archive.ics.uci.edu/ml/machine-learning-databases/mushroom/agaricus-lepiota.data"
mushroomtable = read.table(mushroomurl,header = FALSE,sep=",")
print(head(mushroomtable))
## V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20
## 1 p x s n t p f c n k e e s s w w p w o p
## 2 e x s y t a f c b k e c s s w w p w o p
## 3 e b s w t l f c b n e c s s w w p w o p
## 4 p x y w t p f c n n e e s s w w p w o p
## 5 e x s g f n f w b k t e s s w w p w o e
## 6 e x y y t a f c b n e c s s w w p w o p
## V21 V22 V23
## 1 k s u
## 2 n n g
## 3 n n m
## 4 k s u
## 5 n a g
## 6 k n g
mushroomdf = data.frame(mushroomtable)
mushroomdfnamed = setNames(mushroomdf,c("Edibility","cap-shape","cap-surface","cap-color","bruises","odor",
"gill-attachment","gill-spacing","gill-size","gill-color","stalk-shape","stalk-root",
"stalk-surface-above-ring","stalk-surface-below-ring","stalk-color-above-ring",
"stalk-color-below-ring","veil-type","veil-color","ring-number","ring-type",
"spore-print-color","population","habitat"))
subdf = mushroomdfnamed[,c("Edibility","population","habitat","stalk-shape","odor")]
levels(subdf$Edibility) = c("edible","poisonous")
levels(subdf$population) = c("abundant","clustered","numerous","scattered","several","solitary")
levels(subdf$habitat) = c("woods","grasses","leaves","meadows","paths","urban","waste")
levels(subdf$`stalk-shape`) = c("enlarging","tapering")
levels(subdf$odor) = c("almond","creosote","foul","anise","musty","none","pungent","spicy","fishy")
print(head(subdf))
## Edibility population habitat stalk-shape odor
## 1 poisonous scattered urban enlarging pungent
## 2 edible numerous grasses enlarging almond
## 3 edible numerous meadows enlarging anise
## 4 poisonous scattered urban enlarging pungent
## 5 edible abundant grasses tapering none
## 6 edible numerous grasses enlarging almond