Load Data
url <- getURL("https://raw.githubusercontent.com/baroncurtin2/data607/master/agaricus-lepiota.data.txt")
data <- read.csv(textConnection(url), header = FALSE, sep = ",", stringsAsFactors = FALSE)
Rename Columns
colnames(data) <- c("class", "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")
summary(data)
## class cap-shape cap-surface
## Length:8124 Length:8124 Length:8124
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## cap-color bruises? odor
## Length:8124 Length:8124 Length:8124
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## gill-attachment gill-spacing gill-size
## Length:8124 Length:8124 Length:8124
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## gill-color stalk-shape stalk-root
## Length:8124 Length:8124 Length:8124
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## stalk-surface-above-ring stalk-surface-below-ring stalk-color-above-ring
## Length:8124 Length:8124 Length:8124
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## stalk-color-below-ring veil-type veil-color
## Length:8124 Length:8124 Length:8124
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## ring-number ring-type spore-print-color
## Length:8124 Length:8124 Length:8124
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## population habitat
## Length:8124 Length:8124
## Class :character Class :character
## Mode :character Mode :character
Subset Data & Transform Data
mini <- data %>%
select("class", "cap-shape", "cap-color", "odor") %>%
rename(safe.to.eat = "class", shape = "cap-shape", color = "cap-color") %>%
mutate(safe.to.eat = recode(safe.to.eat, e = "edible", p = "poisonous")) %>%
mutate(shape = recode(shape, b = "bell", c = "conical", x = "convex", f = "flat", k = "knobbed", s = "sunken")) %>%
mutate(color = recode(color, n = "brown", b = "buff", c = "cinnamon", g = "gray", r = "green", p = "pink", u = "purple", e = "red", w = "white", y = "yellow")) %>%
mutate(odor = recode(odor, a = "almond", l = "anise", c = "creosote", y = "fishy", f = "foul", m = "musty", n = "none", p = "pungent", s = "spicy"))
head(mini, 10)
## safe.to.eat shape color odor
## 1 poisonous convex brown pungent
## 2 edible convex yellow almond
## 3 edible bell white anise
## 4 poisonous convex white pungent
## 5 edible convex gray none
## 6 edible convex yellow almond
## 7 edible bell white almond
## 8 edible bell white anise
## 9 poisonous convex white pungent
## 10 edible bell yellow almond
tail(mini, 10)
## safe.to.eat shape color odor
## 8115 poisonous flat cinnamon musty
## 8116 edible convex brown none
## 8117 poisonous knobbed brown spicy
## 8118 poisonous knobbed red fishy
## 8119 poisonous knobbed brown foul
## 8120 edible knobbed brown none
## 8121 edible convex brown none
## 8122 edible flat brown none
## 8123 poisonous knobbed brown fishy
## 8124 edible convex brown none