Week 1 Homework-Data 607-Assignment 1
getwd()
## [1] "C:/Users/Emahayz_Pro/Desktop/Data_Science/Data 607/Week1"
setwd("C:/Users/Emahayz_Pro/Desktop/Data_Science/Data 607/Week1")
# Assignment - Loading Data into a Data Frame
Mushrooms<-read.csv("https://archive.ics.uci.edu/ml/machine-learning-databases/mushroom/agaricus-lepiota.data", header= FALSE, sep=",")[ ,1:4]
Task 1:
You should take the data, and create a data frame with a subset of the columns in the dataset.
You should include the column that indicates edible or poisonous and three or four other columns.
colnames(Mushrooms) <- c("classes", "capshape","capsurface", "capcolor") # Selecting columns
head(Mushrooms) # The original Mushrooms file is successfully read and the columns listed.
## classes capshape capsurface capcolor
## 1 p x s n
## 2 e x s y
## 3 e b s w
## 4 p x y w
## 5 e x s g
## 6 e x y y
Task 2:
You should also add meaningful column names and replace the abbreviations used in the data
# Colname = classes
Mushrooms$classes <-as.character(Mushrooms$classes)
Mushrooms$classes [Mushrooms$classes %in% "e"] <- "edible"
Mushrooms$classes [Mushrooms$classes %in% "p"] <- "poisonous"
# Colname = capshape
Mushrooms$capshape <-as.character(Mushrooms$capshape)
Mushrooms$capshape [Mushrooms$capshape %in% "b"] <- "bell"
Mushrooms$capshape [Mushrooms$capshape %in% "c"] <- "conical"
Mushrooms$capshape [Mushrooms$capshape %in% "x"] <- "convex"
Mushrooms$capshape [Mushrooms$capshape %in% "f"] <- "flat"
Mushrooms$capshape [Mushrooms$capshape %in% "k"] <- "knobbed"
Mushrooms$capshape [Mushrooms$capshape %in% "s"] <- "sunken"
# Colname = capsurface
Mushrooms$capsurface <-as.character(Mushrooms$capsurface)
Mushrooms$capsurface [Mushrooms$capsurface %in% "f"] <- "fibrous"
Mushrooms$capsurface [Mushrooms$capsurface %in% "g"] <- "grooves"
Mushrooms$capsurface [Mushrooms$capsurface %in% "y"] <- "scaly"
Mushrooms$capsurface [Mushrooms$capsurface %in% "s"] <- "smooth"
# Colname = capcolor
Mushrooms$capcolor <-as.character(Mushrooms$capcolor)
Mushrooms$capcolor [Mushrooms$capcolor %in% "n"] <- "brown"
Mushrooms$capcolor [Mushrooms$capcolor %in% "b"] <- "buff"
Mushrooms$capcolor [Mushrooms$capcolor %in% "c"] <- "cinnamon"
Mushrooms$capcolor [Mushrooms$capcolor %in% "g"] <- "gray"
Mushrooms$capcolor [Mushrooms$capcolor %in% "r"] <- "green"
Mushrooms$capcolor [Mushrooms$capcolor %in% "p"] <- "pink"
Mushrooms$capcolor [Mushrooms$capcolor %in% "u"] <- "purple"
Mushrooms$capcolor [Mushrooms$capcolor %in% "e"] <- "red"
Mushrooms$capcolor [Mushrooms$capcolor %in% "w"] <- "white"
Mushrooms$capcolor [Mushrooms$capcolor %in% "y"] <- "yellow"
View the first few rows again
head(Mushrooms)
## classes capshape capsurface capcolor
## 1 poisonous convex smooth brown
## 2 edible convex smooth yellow
## 3 edible bell smooth white
## 4 poisonous convex scaly white
## 5 edible convex smooth gray
## 6 edible convex scaly yellow