2011-08-30 67 views
-1

请给我上了以下一些建议。R滤光片,一个子集数据框

有具有三列的数据帧,第一个是一个日期时间(精确到秒),第二个是一个人的名字,而第三个是一个消息。

我想要检索以下信息,并绘制出来。每人

  1. 消息一定分钟内。
  2. 某个人的某分钟内的信息。

在此先感谢。

+1

您的数据集将真的得到一个有用的反应 – richiemorrisroe

回答

4

有很多的R.不同的日期格式,如果你还没有为他们的一个偏好,然后使用lubridate包。

library(lubridate) 

一些样本数据:

the_present <- now() 
dfr <- data.frame(
    person = rep(c("Richie", "user900168"), each = 3), 
    time = seq(the_present, by = "-1 min", length.out = 6), 
    message = letters[1:6] 
) 

选择一个有趣分钟:

start_time <- floor_date(the_present, unit = "min") 
end_time <- ceiling_date(the_present, unit = "min") 

使用subsettable为您解决问题。

table(subset(dfr, time > start_time & time <= end_time, person)) 
subset(dfr, person == "Richie" & time > start_time & time <= end_time) 
+0

非常感谢你帮助的可重复的例子。对不起,这个问题还不够清楚。 – user900168