I’m pretty sure I should be able to use arrayInd() to do this, but I’m still wrapping my head around R and I am missing something fundamental here.
I have a dataframe that includes two date columns. I calculated a new column with the difference between them. So now I have df$before_date, df$after_date and df$days_out.
I can do this to see the index for the maximum and minimum value in df$days_out:
> which.min(df$days_out)
[1] 18704
> which.max(df$days_out)
[1] 80183
And then I can go through and see the date info:
> df[80183, 5]
[1] "1973-12-17"
> df[80183, 6]
[1] "2010-08-13"
> df[80183, 12]
Time difference of 13388 days
I’m trying to figure out how to do that in one fell swoop, so I’d get a result like:
df$before_date df$after_date df$days_out
[80183] 1973-12-17 2010-08-13 13388
What am I missing here?
Perhaps something like this?
Or you can calculate the max and min values in one pass: