library(RCurl)
## Loading required package: bitops
x <- getURL("https://raw.githubusercontent.com/betsyrosalen/DATA_607_Data_Acquisition_and_Management/master/Assignment1/Mushrooms/agaricus-lepiota.csv") 
mushrooms <-data.frame(read.csv(text=x, header=FALSE))
dim(mushrooms)
## [1] 8124   23
head(mushrooms)
##   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

Rename Column

colnames(mushrooms) <- c("classes", "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", "habitats")
mushrooms <- data.frame(mushrooms) 
head(mushrooms)
##   classes cap.shape cap.surface cap.color bruises odor gill.attachment
## 1       p         x           s         n       t    p               f
## 2       e         x           s         y       t    a               f
## 3       e         b           s         w       t    l               f
## 4       p         x           y         w       t    p               f
## 5       e         x           s         g       f    n               f
## 6       e         x           y         y       t    a               f
##   gill.spacing gill.size gill.color stalk.shape stalk.root
## 1            c         n          k           e          e
## 2            c         b          k           e          c
## 3            c         b          n           e          c
## 4            c         n          n           e          e
## 5            w         b          k           t          e
## 6            c         b          n           e          c
##   stalk.surface.above.ring stalk.surface.below.ring stalk.color.above.ring
## 1                        s                        s                      w
## 2                        s                        s                      w
## 3                        s                        s                      w
## 4                        s                        s                      w
## 5                        s                        s                      w
## 6                        s                        s                      w
##   stalk.color.below.ring veil.type veil.color ring.number ring.type
## 1                      w         p          w           o         p
## 2                      w         p          w           o         p
## 3                      w         p          w           o         p
## 4                      w         p          w           o         p
## 5                      w         p          w           o         e
## 6                      w         p          w           o         p
##   spore.print.color population habitats
## 1                 k          s        u
## 2                 n          n        g
## 3                 n          n        m
## 4                 k          s        u
## 5                 n          a        g
## 6                 k          n        g

subset

mushroomsSubset <- subset(mushrooms, select = c(classes, spore.print.color, population, habitats))
head(mushroomsSubset)
##   classes spore.print.color population habitats
## 1       p                 k          s        u
## 2       e                 n          n        g
## 3       e                 n          n        m
## 4       p                 k          s        u
## 5       e                 n          a        g
## 6       e                 k          n        g
levels(mushroomsSubset$classes) <- c("edible","poisonous")
levels(mushroomsSubset$spore.print.color) <- c("k"="Black", "n"="Brown", "b"="Buff", "h"="Chocolate", "r"="green", "o"="Orange", "u"="Purple", "w"="White", "y"="Yellow'")
levels(mushroomsSubset$population) <- c("Abundant","Clustered","Numerous","Scattered","Several","Solitary'")
levels(mushroomsSubset$habitats) <- c("Grasses","Leaves","Meadows","Paths","Urban","Waste","Woods'")
head(mushroomsSubset)
##     classes spore.print.color population habitats
## 1 poisonous              Buff  Scattered    Waste
## 2    edible         Chocolate   Numerous   Leaves
## 3    edible         Chocolate   Numerous    Paths
## 4 poisonous              Buff  Scattered    Waste
## 5    edible         Chocolate   Abundant   Leaves
## 6    edible              Buff   Numerous   Leaves