Skip to content
Browse files

Save out names as csv file

  • Loading branch information...
1 parent c4945c9 commit f4ffea097aaf8aac5d56aa34440827c9a1874ff9 @hadley committed May 15, 2009
Showing with 258,007 additions and 2 deletions.
  1. +6 −2 3-clean.r
  2. +258,001 −0 baby-names.csv
View
8 3-clean.r
@@ -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")
@@ -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)
View
258,001 baby-names.csv
258,001 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.

0 comments on commit f4ffea0

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