Skip to content

Instantly share code, notes, and snippets.

@cigrainger
Created February 13, 2014 17:13
Show Gist options
  • Save cigrainger/8979392 to your computer and use it in GitHub Desktop.
Save cigrainger/8979392 to your computer and use it in GitHub Desktop.
prep.comp <- function(x){
if (names(x)[1]!='Week'){
stop("The first column should be 'Week'. Check the data.")
}
x[['Week']] <- as.character(x[['Week']])
x[['weekstart']] <- strsplit(x[['Week']],split=' - ',fixed=TRUE)[[1]]
x[['weekend']] <- strsplit(x[['Week']],split=' - ',fixed=TRUE)[[2]]
x[['weekstart']] <- as.Date(x[['weekstart']],format='%Y-%m-%d')
x[['weekend']] <- as.Date(x[['weekend']],format='%Y-%m-%d')
return(x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment