Created
June 17, 2017 07:01
-
-
Save mkim0710/44ff9fe1382c37a6967b6bfe18307f32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| url_Data <- readLines("https://raw.githubusercontent.com/issactoast/Machine-Learning-with-R/master/Data/house.txt") %>% paste(collapse = "\n") | |
| houseData <- read.table(text = url_Data, header = FALSE, sep = ":") | |
| houseData | |
| for (i in 1:dim(houseData)[2]){ | |
| houseData[,i] <- gsub(paste("",i), "", houseData[,i]) | |
| } | |
| houseData <- houseData %>% unlist() %>% as.numeric() %>% matrix(ncol = 14) | |
| colnames(houseData) <- c("MEDV", "CRIM", "ZN", "INDUS", | |
| "CHAS", "NOX", "RM", "AGE", | |
| "DIS", "RAD", "TAX", "PTRATIO", | |
| "B", "LSTAT") | |
| ################ | |
| library(tidyverse) | |
| houseData2 <- read_csv("https://raw.githubusercontent.com/issactoast/Machine-Learning-with-R/master/Data/house.txt", col_names = F) | |
| houseData2 = houseData2 %>% separate(col = X1, into = letters[1:14], sep = " [0-9]{1,2}:") | |
| houseData2 = houseData2 %>% map_df(as.numeric) %>% as.matrix | |
| colnames(houseData2) <- c("MEDV", "CRIM", "ZN", "INDUS", | |
| "CHAS", "NOX", "RM", "AGE", | |
| "DIS", "RAD", "TAX", "PTRATIO", | |
| "B", "LSTAT") | |
| identical(houseData, houseData2) | |
| # > identical(houseData, houseData2) | |
| # [1] TRUE | |
| ################ | |
| library(tidyverse) | |
| houseData3 = read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/housing/housing.data", col_names = F) | |
| houseData3 = houseData3 %>% separate(col = X1, into = letters[1:14], sep = "[[:space:]]+") | |
| houseData3 = houseData3 %>% map_df(as.numeric) %>% as.matrix | |
| colnames(houseData3) <- c("MEDV", "CRIM", "ZN", "INDUS", | |
| "CHAS", "NOX", "RM", "AGE", | |
| "DIS", "RAD", "TAX", "PTRATIO", | |
| "B", "LSTAT") | |
| identical(houseData, houseData3) | |
| # > identical(houseData, houseData3) | |
| # [1] FALSE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment