Skip to content

Instantly share code, notes, and snippets.

@statwonk
Last active August 29, 2015 13:57
Show Gist options
  • Save statwonk/9448932 to your computer and use it in GitHub Desktop.
Save statwonk/9448932 to your computer and use it in GitHub Desktop.
Reading the FBI data in.
df <- read.csv("data.csv",
header = T,
stringsAsFactors = F)
df$date_put_on_list <- as.POSIXct(df$date_put_on_list, format = "%m/%d/%Y", tz = "EST")
df$follow_up_date <- as.POSIXct(df$follow_up_date, format = "%m/%d/%Y", tz = "EST")
df$days_to_capture <- ifelse(is.na(df$follow_up_date) | df$follow_up_date == "",
difftime(Sys.time(), df$date_put_on_list, units = "days"),
difftime(df$follow_up_date, df$date_put_on_list, units = "days"))
df$censor <- ifelse(!is.na(df$follow_up_date), 1, 0)
mean(df$days_to_capture[df$days_to_capture > 0 & df$censor == 1], na.rm = T)
[1] 402.2239 # days
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment