Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 00:01:30 HMS时间(如有其他情况)_R_Dplyr_Lubridate - Fatal编程技术网

R 00:01:30 HMS时间(如有其他情况)

R 00:01:30 HMS时间(如有其他情况),r,dplyr,lubridate,R,Dplyr,Lubridate,我有一列指示时间戳: [1] 00:01:30 [2] 00:02:45 [50]01:02:05 我想把这些时间用于IF语句。 我尝试过使用lubridate::hms() 它可以工作,但它改变了以下格式: “00:01:30”至“1M 30秒” 我只希望时间戳保持“00:01:30”的格式,并将其用于条件。 例如: mutate(times=ifelse(时间戳>“00:20:31”,1,2)) 非常感谢 这是否有效: library(dplyr) library(lubridate)

我有一列指示时间戳:

[1] 00:01:30

[2] 00:02:45

[50]01:02:05

我想把这些时间用于IF语句。 我尝试过使用lubridate::hms() 它可以工作,但它改变了以下格式: “00:01:30”至“1M 30秒”

我只希望时间戳保持“00:01:30”的格式,并将其用于条件。 例如:
mutate(times=ifelse(时间戳>“00:20:31”,1,2))

非常感谢

这是否有效:

library(dplyr)
library(lubridate)
df %>% mutate( times = case_when(hms(timestamp) > hms('00:20:31') ~ 1, TRUE ~ 2))
# A tibble: 3 x 2
  timestamp times
  <chr>     <dbl>
1 00:01:30      2
2 00:02:45      2
3 01:02:05      1
库(dplyr)
图书馆(lubridate)
df%>%变异(times=case_当(hms(timestamp)>hms('00:20:31')~1,TRUE~2))
#一个tibble:3x2
时间戳时间
1 00:01:30      2
2 00:02:45      2
3 01:02:05      1
使用的数据:

df
# A tibble: 3 x 1
  timestamp
  <chr>    
1 00:01:30 
2 00:02:45 
3 01:02:05 
df
#一个tibble:3x1
时间戳
1 00:01:30 
2 00:02:45 
3 01:02:05