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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -