如何根据字符串从字符串中创建一个循环以提取行
希望根据该行是否包含字符串中列出的任何DateTime邮票并将其添加到新的数据框架中,从而从大数据框架中提取行。
示例数据框架和DateTime邮票的字符串。
df <- data.frame(
Date = c("2017/05/10 15:00", "2017/05/10 22:00", "2017/05/25 10:00", "2017/05/25 20:00"),
value = c(15, 10, 25, 7)
)
df$Date <- as.POSIXlt(df$Date, tz ="GMT", origin = '1970-01-01')
dtlist <- c("2017/05/10 22:00", "2017/05/25 20:00") # desired datetimes
寻找这样的输出:
Date Value
2017/05/10 22:00 10
2017/05/25 20:00 7
首先考虑是使用wher()
来识别行,但不知道如何整合从dtlist读取变量的条件。
例如哪个(df $ value == dtlist(i))
我是列表中的nth对象
Looking to extract rows from a large data frame based on whether the row contains any of the datetime stamps listed in a character string and add them to a new data frame.
Example data frame and character string of datetime stamps.
df <- data.frame(
Date = c("2017/05/10 15:00", "2017/05/10 22:00", "2017/05/25 10:00", "2017/05/25 20:00"),
value = c(15, 10, 25, 7)
)
df$Date <- as.POSIXlt(df$Date, tz ="GMT", origin = '1970-01-01')
dtlist <- c("2017/05/10 22:00", "2017/05/25 20:00") # desired datetimes
Looking for output like this:
Date Value
2017/05/10 22:00 10
2017/05/25 20:00 7
First thought was to use which()
to identify the rows but don't know how to incorporate the condition of reading the variables from dtlist.
e.g. which(df$value == dtlist(i))
where i is nth object in the list
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论