Last active
August 29, 2015 13:57
-
-
Save statwonk/9448932 to your computer and use it in GitHub Desktop.
Reading the FBI data in.
This file contains 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
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