Skip to content

Commit

Permalink
Save out names as csv file
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed May 15, 2009
1 parent c4945c9 commit f4ffea0
Show file tree
Hide file tree
Showing 2 changed files with 258,007 additions and 2 deletions.
8 changes: 6 additions & 2 deletions 3-clean.r
Expand Up @@ -3,6 +3,9 @@ library(plyr)
files <- dir("raw", full = T)
names(files) <- gsub("\\.csv", "", dir("raw"))

# Load all csv files into a single data frame and give informative column
# names

bnames <- ldply(files, read.csv, header = F, skip = 1, nrows = 1000,
stringsAsFactors = FALSE)
names(bnames) <- c("year", "rank", "boy_name", "boy_percent", "girl_name", "girl_percent")
Expand All @@ -17,8 +20,9 @@ girls$sex <- "girl"

all <- rbind(boys, girls)

# Turn percent string into a number
# Turn year and percent into a real numbers
all$percent <- as.numeric(gsub("%", "", all$percent)) / 100
all$year <- as.numeric(as.character(all$year))

write
# Save as csv
write.table(all, "baby-names.csv", sep=",", row = F)

0 comments on commit f4ffea0

Please sign in to comment.