Created
January 14, 2011 21:14
-
-
Save Protonk/780251 to your computer and use it in GitHub Desktop.
Preprocessing and simple display of launches
This file contains hidden or 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
| ####Pre-processing of launch log before sending it to Google Refine#### | |
| #The vector of widths can be grabbed a number of ways: by hand, with regular expressions, or from a file explaining the structure | |
| launch.width<-c(12,27,15,31,26,9,24,16,9,12,5,19) | |
| #Your file path will vary, of course | |
| launch.path<-c("/Users/protonk/Dropbox/Past Econ Work/Launch vehicle market/Complete text launch log.txt") | |
| launch.names<- c("Launch","Date","COSPAR","PL.Name","Orig.PL.Name","SATCAT","LV.Type","LV.SN","Site","Subsite","Success","Ref") | |
| #Read in FWF and export a .csv | |
| launch.test<-read.fwf(launch.path,launch.width,header=FALSE,skip=2,as.is=TRUE,col.names=launch.names) | |
| write.csv(launch.test,file="~/R/launch.csv") | |
| ########## | |
| ##Google Refine Magick | |
| ########## | |
| library(ggplot2) | |
| library(plyr); | |
| ########Processing of the exported file | |
| launch.trimmed<-read.csv("~/Downloads/launch.csv",as.is=TRUE) | |
| #This is just to make looking at summary and structure easier | |
| launch.min<-subset(launch.trimmed,select=c(Launch,Date,Year,Orig.PL.Name,Site,Success,Lat,Long)) | |
| #Note to self, don't make year a factor (year was a variable I created in Google Refine) | |
| launch.min$Site<-as.factor(launch.min$Site) | |
| launch.min$Date<-as.Date(launch.min$Date,"%Y %b %d") | |
| #The dataset is pretty much complete, the NA's are piggyback launches | |
| launch.min<-launch.min[which(complete.cases(launch.min)),] | |
| names(launch.min)<-tolower(names(launch.min)) | |
| #By year/site summary stats | |
| launch.sum<-ddply(launch.min,c("site","year"),"nrow") | |
| names(launch.sum)<-c("site","year","launches") | |
| #The plot | |
| launch.plot<-qplot(year,launches,data=launch.sum,group=site,colour=site,geom="line")+opts(legend.position = "none")+scale_y_continuous(name="Launches per Year")+scale_x_continuous(name='') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment