Sorting within each category separately in R -
i have set of 4000 data points, each specifying time @ incident happened , site @ happened, , there 165 sites. want list of inter-incident times @ each site.
if there 1 site, sort times increasing order (t_1 < t_2 < ... < t_n) , find differences s_{n+1} = t_{n+1}-t_n. want separately @ each site.
ultimately each data point specify site , list of inter-incident times.
another complication: may worth keeping inter-incident times in chronological order.
the r commands
sort(times)
and
site[order(times)]
would me somewhere if didn't want each site separately.
how can in r?
using dplyr
, this, depending on how data laid out (a dput help):
library(dplyr) df %>% group_by(site) %>% arrange(times) %>% mutate(difference = c(0, diff(times)))
Comments
Post a Comment