【发布时间】:2017-10-26 13:45:18
【问题描述】:
我有这个数据集:
> dput(SampleEvents)
structure(list(Event = structure(c(10L, 5L, 6L, 11L, 10L, 7L,
11L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 11L), .Label = c("e10", "e11",
"e12", "e13", "e2", "e3", "e6", "e8", "e9", "Login", "Logout"
), class = "factor"), Transaction.ID = structure(c(NA, 1L, NA,
2L, NA, NA, NA, NA, 3L, NA, NA, NA, NA, NA, NA), .Label = c("t1",
"t4", "t5"), class = "factor"), User.ID = structure(c(1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("kenn1",
"kenn2"), class = "factor"), Event.Date = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "20/5/2017", class = "factor"),
Event.Time = structure(c(12L, 13L, 14L, 15L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L), .Label = c("10:01", "10:02",
"10:03", "10:04", "10:05", "10:06", "10:07", "10:08", "10:09",
"10:10", "10:11", "9:00", "9:30", "9:45", "9:50"), class = "factor")), .Names = c("Event",
"Transaction.ID", "User.ID", "Event.Date", "Event.Time"), class = "data.frame", row.names = c(NA,
-15L))
我想删除“事件”列下两个固定值内的所有行,即从“登录”到“注销”的行,这些行在“登录”和“注销”之间缺少所有交易 ID 值:
我还想保留数据集的当前顺序。
我如何在 R 中做到这一点?
【问题讨论】:
-
请不要以图片形式提供您的数据。对于任何人使用它,他们都需要再次输入。相反,请使用文本格式。理想情况下,您将拥有 R 中的数据并使用
dput来提供数据结构。您的图像看起来像是来自 Excel。 至少您可以保存为 csv 并将其粘贴到您的问题中。 -
我对这个网站有点陌生。让我尝试附加数据集。
-
是的,我想在这里有一个示例并了解逻辑,以便我可以将它应用到我的父数据集中。