I am reading data from a website: https://raw.github.com/johnmyleswhite/ML_for_Hackers/master/02-Exploration/data/01_heights_weights_genders.csv
(1) At first I attempted to read the data directly into R with the following code:
raw_data <- read.table("https://raw.github.com/johnmyleswhite/ML_for_Hackers/master/02-Exploration/data/01_heights_weights_genders.csv", stringsAsFactors=FALSE)
But I received the following error:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : unsupported URL scheme
So I simply copied the data into a .csv file. I saved this file as "Raw_Data.csv" in a directory. The data is, however, all in one column.
(2) I read this file into R via the following code
raw_data <- read.csv("Raw_Data.csv", stringsAsFactors=FALSE)
What I would like to do is split this one column into three, with the column names as "Gender", "Height", "Weight". What I tried was this:
for(i in 1:nrow(raw_data)){
raw_data$Gender[i] <- strsplit(raw_data$Gender[i], ",")[[1]][1]
raw_data$Height[i] <- strsplit(raw_data$Height[i], ",")[[1]][2]
raw_data$Weight[i] <- strsplit(raw_data$Weight[i], ",")[[1]][3]
}
However, I get this error:
Error in strsplit(raw_data$Gender[i], ",") : non-character argument
Thank you in advance for your help!
may be it was because of quotes,
try
raw_data <- read.csv("Raw_Data.csv", stringsAsFactors=FALSE, quotes="\"")