如何使用包含日期的词典对数组进行排序?

时间:2016-12-08 19:44:28

标签: arrays swift sorting date

在我的Swift项目中,Array位于Dictionaries。每个Dictionary都包含String date。如何从最新到最早获得Array date的新{?}}?谢谢!

var array = [["date":"2016-02-12","title":"1"],["date":"2014-05-12","title":"2"],["date":"2016-06-18","title":"3"],["date":"2015-09-17","title":"4"]]

1 个答案:

答案 0 :(得分:2)

像这样:

df.in <- df.in %>% 
  mutate(arrive_min=round_date(t.arrive, "mins"))
df2 <- df.in %>% 
  group_by(id, loc, arrive_min) %>% 
  do(data.frame(id=.$id, loc=.$loc, mins = .$arrive_min + (0:floor(.$idle/60))*60))
df.in$mins <- df.in$arrive_min
left_join(df2, df.in, by=c("id", "loc", "mins")) %>%  
  group_by(id, loc, arrive_min.x) %>% 
  do(data.frame(min1=.$mins, idle=c(rep(60, .$idle[1]/60), .$idle[1]%%60))) %>% 
  group_by(min1, loc) %>% 
  summarise(ave_idle=mean(idle)) 


#                  min1  loc.x ave_idle
#                <dttm> <fctr>    <dbl>
#1  2015-03-01 08:00:00      B 60.00000
#2  2015-03-01 08:01:00      B 60.00000
#3  2015-03-01 08:02:00      B 60.00000
#4  2015-03-01 08:03:00      B 12.00000
#5  2015-03-01 08:10:00      A 51.66667
#6  2015-03-01 08:11:00      A 60.00000
#7  2015-03-01 08:12:00      A 21.50000
#8  2015-03-01 08:12:00      C  5.00000
#9  2015-03-01 08:17:00      B 28.00000
#10 2015-03-01 08:20:00      B  1.00000
#11 2015-03-01 08:20:00      C  0.00000
#12 2015-03-01 08:23:00      A 30.00000
#13 2015-03-01 08:24:00      A 46.00000