我有一个根据 diff 或 difftime 的问题。
Equip <- c(1001,1001,1001,1002,1002,1002,1003,1003,1003,1003,1003,1003,1003,1003)
Notif <- c(321,322,322,319,319,345,495,495,495,441,441,441,471,471)
Job <- c("01.01.2011","05.01.2011","05.01.2011","05.01.2011","05.01.2011",
"15.01.2011","23.03.2011","23.03.2011","23.03.2011","27.03.2011","27.03.2011",
"27.03.2011","29.03.2011",
"29.03.2011")
Job <- as.Date(Job,format="%d. %m. %Y")
df <- data.frame(Equip,Notif,Job)
我想在 data.frame 中有一个新列,时间差 [以天为单位] 应该是。
计算时差的条件如下:我现在要做的是,如果Equipnumber相同,但Notifnumber不同,我想要时差(Jobdate)
输出应该是这样的:
df$dd <- c(0,4,4,0,0,10,0,0,0,4,4,4,2,2)
(对于Equipnumber中的第一个Notifnumber,dd为0,因为是第一次访问)
希望你能帮助我,我试着去做,但我不能像我想要的那样去做。
我只能使用没有任何软件包的标准 R 程序...
根据给定的链接,我创建了以下示例,该示例也不起作用:
也许你可以帮助我:
Equips <- c(10006250,10006252,10006252,10006252,10006252,10006252,10006252,
10006252,10006252,10006252,10006252,10006252,10006252,10006252,10006252,10006777)
Notifs <- c(306863771,306862774,306862774,306862774,306933440,
306933440,306998451,306998451,307024311,307024311,
307024311,307024311,307033136,307033136,307128754,307158697)
Jobs <- c("25.01.2011","23.06.2011","23.06.2011","23.06.2011","28.06.2011",
"28.06.2011","02.07.2011","02.07.2011","03.09.2011","03.09.2011",
"03.09.2011","03.09.2011","05.09.2011","05.09.2011","02.11.2011","05.05.2011")
Comps <- c("Service Boiler","General Boiler Components","Ignition and Flame Detection",
"Service Boiler!!!","Electrical Components","Gas Train Assembly",
"Control Box"," Ignition and Flame Detection","CH Components Active",
"CH Components Passive","CH Components Passive","DHW Components",
"DHW Components","Internal Pipeworks and Connections","not grouped in WCC",
"Service Boiler")
Category <- c("service_repair","service_repair","service_repair",
"service_repair","repair","repair","repair","repair","repair","repair",
"repair","repair","repair","repair","repair","service_repair")
Job <- as.Date(Job,format="%d. %m. %Y")
df <- data.frame(Equips,Notifs,Jobs,Comps,Category)
我真的不知道为什么它不适用于此,但是根据第一篇文章中的数据,也许您可以帮助我。