Launch into space

[This article was first published on Wiekvoet, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I saw a link to a list with all rocket launches into space the other day. This post contains some plots concerning day of launch made from that.


Data is a fixed format file with eleven columns. Reading fixed format is not very difficult, however, it requires a bit of preparation. In this case, the first row contains a description of the columns, the second a number of ‘#’signs to denote the start of the columns. I found it most logical to first get the column widths, use these to create the variable names and then read the data. There is an interesting detail, the first two rows have ‘#’ as first character, read.fwf has this as default comment character and skips them.
r1 <- readLines('launchlog.txt')
colwidth  <- gregexpr('#',r1[2])[[1]] %>%
    c(.,max(nchar(r1))) %>%

cols <- read.fwf(textConnection(r1[1]),
        comment.char=’@’) %>%
    unlist(.) %>%
    make.names(.) %>%
    gsub(‘\.+$’,”,.) # remove extra . at end of string

r2 <- read.fwf('launchlog.txt',
Some launches contain more than one pay load. These are represented by rows containing just pay load information. These are removed by removing all records without a success value. In addition, a date variable is created using the launch date. Extra spaces, a consequence of the fixed input format, are removed from the suc variable.
r3 <- filter(r2,!
Sys.setlocale(category = “LC_TIME”, locale = “C”)
r3$Date <- as.Date(r3$Launch.Date..UTC,format='%Y %b %d')
levels(r3$Suc) <- gsub(' *','',levels(r3$Suc))



Since I wanted proportion of days with a launch, I created a few extra data frames. alldays contains all dates. monthorder and wdorder provide additional variables intended to arrange the months and week days in a reasonable order.
alldays <- data.frame(
        max(r3$Date) ,
        by=1 ))

monthorder <- alldays %>%
        mn=format(Date,’%m’)) %>%
    select(.,month,mn) %>%
    unique(.) %>%

wdorder <- alldays %>%
        wdn=format(Date,’%u’)) %>%
    select(.,wd,wdn) %>%    
    unique(.) %>%

By month

January seems to get least launches. On the other hand December most. I wonder if that is publicity seeking in December of the well know January 1st deadline.

By weekdays

As expected, middle of the week gets most launches. The lower value for Monday than Saturday suggests the day before a launch is just as busy as the day of launch itself.
numlawd <-    mutate(r3,
        wd =factor(weekdays(Date),levels=wdorder$wd)) %>%
    xtabs( ~ wd,.) %>% %>%
numwd <-    mutate(alldays,
        wd =factor(weekdays(Date),levels=wdorder$wd)) %>%
    xtabs( ~ wd,.) %>% %>%
propbwd <- merge(numlawd,numwd) %>%
qplot(y=prop,x= wd,data=propbwd) +
    ylab(‘Proportion’) +
    xlab(‘Day of Week’) +
    ggtitle(‘Proportion Week Days with Launch’) +

By year

For years I have made a split between success and fail. It is also the most interesting of plots. Proportion launches per day increases quickly in the first years, as does the chance of a success. By mid eighties the launches decrease, only to pick up in the new millennium. The end of the space race is not visible in the number of launches, but seems to coincide with less failed launches. 
numlayr <- mutate(r3,year =factor(format(Date,'%Y'))) %>%
    xtabs( ~ year + Suc,.) %>% %>%
numyr <-    mutate(alldays,year =factor(format(Date,'%Y'))) %>%
    xtabs( ~ year,.) %>% %>%
propyr <- merge(numlayr,numyr) %>%
qplot(y=prop,x= Year,colour=Suc,data=propyr) +
    ylab(‘Proportion’) +
    xlab(‘Year’) +
    ggtitle(‘Proportion Days with Launch’) +

Most busy day?

Once there were four launches on a day.
r3 %>% xtabs(~factor(Date,levels=as.character(alldays$Date)),.) %>% %>%
    rename(.,Nlaunch=Freq) %>%
    xtabs(~Nlaunch,.) %>% 
  Nlaunch  Freq
1       0 16154
2       1  4224
3       2   562
4       3    44
5       4     1

To leave a comment for the author, please follow the link and comment on their blog: Wiekvoet. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)