R中的时间轴错误:“分钟”对因素没有意义

时间:2019-11-26 15:16:58

标签: r timeline

我的原始数据集

df

   bugid           timestamp                    commenter     Owner.
1  18348 2011-07-10 12:26:00        nick.sho...@gmail.com     No
2  18348 2011-07-11 10:47:16 ralf%and...@gtempaccount.com     No
3  18348 2011-07-11 17:44:50           tnor...@google.com    Yes
4  18348 2011-07-11 18:13:17             nic...@gmail.com     No
5  18348 2011-07-11 18:14:39        nick.sho...@gmail.com     No
6  18348 2011-07-11 18:23:54        nick.sho...@gmail.com     No
7  18348 2011-07-13 14:36:31           vt903...@gmail.com     No
8  18348 2011-07-15 18:16:12           tnor...@google.com    Yes
9  18348 2011-07-15 18:17:54           tnor...@google.com    Yes
10 18348 2011-07-26 06:35:04           hustd...@gmail.com     No
11 18348 2011-09-04 21:34:03        baykalca...@gmail.com     No
12 18348 2011-09-13 23:14:20           tnor...@google.com    Yes
13 18348 2011-10-19 18:49:22             x...@android.com     No
  

dput(df)

structure(list(bugid = c(18348L, 18348L, 18348L, 18348L, 18348L, 
18348L, 18348L, 18348L, 18348L, 18348L, 18348L, 18348L, 18348L
), timestamp = structure(1:13, .Label = c("2011-07-10 12:26:00", 
"2011-07-11 10:47:16", "2011-07-11 17:44:50", "2011-07-11 18:13:17", 
"2011-07-11 18:14:39", "2011-07-11 18:23:54", "2011-07-13 14:36:31", 
"2011-07-15 18:16:12", "2011-07-15 18:17:54", "2011-07-26 06:35:04", 
"2011-09-04 21:34:03", "2011-09-13 23:14:20", "2011-10-19 18:49:22"
), class = "factor"), commenter = structure(c(4L, 5L, 6L, 3L, 
4L, 4L, 7L, 6L, 6L, 2L, 1L, 6L, 8L), .Label = c("baykalca...@gmail.com", 
"hustd...@gmail.com", "nic...@gmail.com", "nick.sho...@gmail.com", 
"ralf%and...@gtempaccount.com", "tnor...@google.com", "vt903...@gmail.com", 
"x...@android.com"), class = "factor"), Owner. = structure(c(1L, 
1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L), .Label = c("No", 
"Yes"), class = "factor")), class = "data.frame", row.names = c(NA, 
-13L))

然后我执行以下操作:

df$date <- as.Date(df$timestamp)

数据集因此变为:

df
   bugid           timestamp                    commenter Owner.       date
1  18348 2011-07-10 12:26:00        nick.sho...@gmail.com     No 2011-07-10
2  18348 2011-07-11 10:47:16 ralf%and...@gtempaccount.com     No 2011-07-11
3  18348 2011-07-11 17:44:50           tnor...@google.com    Yes 2011-07-11
4  18348 2011-07-11 18:13:17             nic...@gmail.com     No 2011-07-11
5  18348 2011-07-11 18:14:39        nick.sho...@gmail.com     No 2011-07-11
6  18348 2011-07-11 18:23:54        nick.sho...@gmail.com     No 2011-07-11
7  18348 2011-07-13 14:36:31           vt903...@gmail.com     No 2011-07-13
8  18348 2011-07-15 18:16:12           tnor...@google.com    Yes 2011-07-15
9  18348 2011-07-15 18:17:54           tnor...@google.com    Yes 2011-07-15
10 18348 2011-07-26 06:35:04           hustd...@gmail.com     No 2011-07-26
11 18348 2011-09-04 21:34:03        baykalca...@gmail.com     No 2011-09-04
12 18348 2011-09-13 23:14:20           tnor...@google.com    Yes 2011-09-13
13 18348 2011-10-19 18:49:22             x...@android.com     No 2011-10-19

我删除了timestamp列,认为该列必定会引起问题:

remove.cols = names(df) %in% c("timestamp")
df.pruned <- df[!remove.cols]

但是,当我尝试使用以下方法生成时间轴时:

timelineS(df.pruned)

我得到了错误:

  

Summary.factor(c(4L,5L,6L,3L,4L,4L,7L,6L,6L,2L,1L,   :“分钟”对因素没有意义

在读取类似问题的线程后,尝试将日期字段转换为数字。但是似乎没有什么可以解决问题。 请帮忙。

1 个答案:

答案 0 :(得分:0)

timelineS软件包的文档指出,您为timelineS函数提供的数据框只能由两列组成-一列用于事件,一列用于日期:

https://www.rdocumentation.org/packages/timelineS/versions/0.1.1/topics/timelineS

您的目标是制定一个时间表来显示各种评论者发表评论的日期吗?

如果是这样,只需将数据框剥离到注释器字段和日期字段即可。

 library(dplyr)
 df_pruned <- df %>%
 select(c("commenter", "date"))

 library(timelineS)
 timelineS(df_pruned)

应该让您开始...您可能希望探索一些格式设置选项,以使时间轴更具视觉吸引力。