从 R 中的时间向量中减去 10 分钟?
问题描述:
我有一列这样的时间:
"2:43::00 PM"
"2:43:01 PM"
"2:43:05 PM"
"2:43:06 PM"
"2:43:07 PM"
我想转到每一行并从每个时间中减去 10 分钟,使新列看起来像这样:
I want to go to each of the row and subtract 10 minutes from each of the time such that the new column looks like this:
"2:33::00 PM"
"2:33:01 PM"
"2:33:05 PM"
"2:33:06 PM"
"2:33:07 PM"
我正在使用
difftime(strptime(data$time[i],format="%H:%M:%S"),strptime("00:10:00",format="%H:%M:%S"))
,但它没有显示正确的结果.
, but it is not showing correct results.
我该如何解决这个问题?
How can i approach this problem?
答
尝试
format(strptime(str1, format = "%I:%M:%S %p") - 10*60, "%I:%M:%S %p")
#[1] "02:33:00 PM" "02:33:01 PM" "02:33:05 PM" "02:33:06 PM" "02:33:07 PM"
数据
str1 <- c("2:43:00 PM", "2:43:01 PM", "2:43:05 PM", "2:43:06 PM", "2:43:07 PM")