删除小于指定值的所有时间

编程入门 行业动态 更新时间:2024-10-25 00:29:49
本文介绍了删除小于指定值的所有时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这可能是一个简单的问题,但我是R的新手,无法找到答案(或谷歌搜索错误的东西)。 我目前正在处理一个项目,该项目涉及删除少于5分钟的所有时间值。使用lubridate包创建时间的数据示例如下。

This is probably a simple question however I am new to R and couldn't find an answer (or was googling the wrong thing). I am currently working on a project which involves deleting all Time values that are less than 5 minutes. An example of the data is as follows with the times created using the "lubridate" package.

Time 19S 1M 24S 7M 53S 11M 6S . . .

现在我希望删除所有小于5分钟的值。因此,我希望得到的最终数据集是:

Now I wish to delete all values which are less than 5 minutes. Therefore the final dataset I wish to get is:

Time 7M 53S 11M 6S . . .

任何帮助都会令人惊叹! 谢谢!

Any help would be amazing! Thanks!

推荐答案

你可以这样做:

df <- df[df$time > ms('5:00'), ]

结果:

> df time value 3 7M 53S 3 4 11M 6S 4

足够苛刻,将其转换为dplyr代码;它不起作用:

Strangly enough, converting this to dplyr code; it doesn't work:

filter(df, time > ms('5:00'))

结果:

time 1 53S 2 1M 6S Warning message: In format.data.frame(x, digits = digits, na.encode = FALSE) : corrupt data frame: columns will be truncated or padded with NAs

我问了一个关于它的问题并找到了答案此处。你得到了很好的解决方案:

I asked a question about that and found a answer here. you get the good solution with:

df %>% mutate(time = as.numeric(time)) %>% filter(time > as.numeric(ms('5:00'))) %>% mutate(time = ms(paste0(floor(time/60),':',round((time/60 - floor(time/60))*60))))

数据:

df <- data.frame(time = ms(c('0:19','1:24','7:53','11:6')), value = 1:4)

更多推荐

删除小于指定值的所有时间

本文发布于:2023-11-29 23:05:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647902.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!