Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Save out names as csv file

  • Loading branch information...
commit f4ffea097aaf8aac5d56aa34440827c9a1874ff9 1 parent c4945c9
Hadley Wickham authored

Showing 2 changed files with 258,007 additions and 2 deletions. Show diff stats Hide diff stats

  1. +6 2 3-clean.r
  2. +258,001 0 baby-names.csv
8 3-clean.r
@@ -3,6 +3,9 @@ library(plyr)
3 3 files <- dir("raw", full = T)
4 4 names(files) <- gsub("\\.csv", "", dir("raw"))
5 5
  6 +# Load all csv files into a single data frame and give informative column
  7 +# names
  8 +
6 9 bnames <- ldply(files, read.csv, header = F, skip = 1, nrows = 1000,
7 10 stringsAsFactors = FALSE)
8 11 names(bnames) <- c("year", "rank", "boy_name", "boy_percent", "girl_name", "girl_percent")
@@ -17,8 +20,9 @@ girls$sex <- "girl"
17 20
18 21 all <- rbind(boys, girls)
19 22
20   -# Turn percent string into a number
  23 +# Turn year and percent into a real numbers
21 24 all$percent <- as.numeric(gsub("%", "", all$percent)) / 100
22 25 all$year <- as.numeric(as.character(all$year))
23 26
24   -write
  27 +# Save as csv
  28 +write.table(all, "baby-names.csv", sep=",", row = F)
258,001 baby-names.csv
258,001 additions, 0 deletions not shown

0 comments on commit f4ffea0

Please sign in to comment.
Something went wrong with that request. Please try again.