Created
August 3, 2015 22:54
-
-
Save scottpham/d3caf52f2139ecf6e128 to your computer and use it in GitHub Desktop.
This file contains 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
#create new (empty) data frame for output | |
df <- data.frame() | |
#read source dataframe | |
sourceData <- read.csv("originals/rentBoard-clean.csv", stringsAsFactors = F) | |
#get max rows | |
maxRows <- nrow(sourceData) | |
for(i in 1:maxRows){ | |
#subset row | |
row <- sourceData[i,] | |
#subset scell | |
name_cell <- row[,"Landlord.Name"] | |
if(str_detect(name_cell, "\n") ){ | |
#split column into list of character vectors | |
names <- suppressWarnings(strsplit(name_cell, '\n')) | |
#for each in character vector | |
for(name in names[[1]]){ | |
#duplicate source row, replacing ['column'] value with each | |
row$Landlord.Name = name | |
#write this row to the new dataframe | |
df <- rbind(df, row) | |
} | |
} | |
#else write original row to empty data frame | |
else df <- rbind(df, row) | |
print(i) | |
} | |
#write new data frame to output | |
write.csv(df, "output/rent_board_split.csv", row.names=FALSE) | |
print("DUNZO") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment