当我尝试对我的 data.table 进行子集化时,我正在丢失数据。
这是写入文件的 .csv
Timestamp,Date,Time,SN,A.Ms.Amp,A.Ms.Vol,A.Ms.Watt,Pac
2013-10-01 12:00:00,2013-10-01,12:00:00,2110000001,23.04,465.43,10723,13544.5
2013-10-01 12:00:00,2013-10-01,12:00:00,2110000002,7.81,474.16,3704,6860
2013-10-01 12:00:00,2013-10-01,12:00:00,2110000003,6.97,484.19,3374,6661
2013-10-01 12:05:00,2013-10-01,12:05:00,2110000001,23.19,467.05,10830,13576
2013-10-01 12:05:00,2013-10-01,12:05:00,2110000002,8.4,462.52,3883.5,7366.5
2013-10-01 12:05:00,2013-10-01,12:05:00,2110000003,7.72,470.6,3631,7169
2013-10-01 12:10:00,2013-10-01,12:10:00,2110000001,23.98,470.29,11278.5,14127.5
2013-10-01 12:10:00,2013-10-01,12:10:00,2110000002,8.62,458.47,3952,7475.5
2013-10-01 12:10:00,2013-10-01,12:10:00,2110000003,7.9,462.62,3654,7182.33
2013-10-01 12:15:00,2013-10-01,12:15:00,2110000001,24.27,467.37,11342,14193
2013-10-01 12:15:00,2013-10-01,12:15:00,2110000002,8.61,458.96,3949,7502
2013-10-01 12:15:00,2013-10-01,12:15:00,2110000003,8.13,458.31,3725,7338
2013-10-01 12:20:00,2013-10-01,12:20:00,2110000001,22.3,461.71,10279.5,12735.5
2013-10-01 12:20:00,2013-10-01,12:20:00,2110000002,8.51,461.87,3929,7553.5
2013-10-01 12:20:00,2013-10-01,12:20:00,2110000003,7.83,462.19,3618.5,7331.5
这是我运行的代码:
library(data.table)
a<-fread("complete1.csv")
a[,`:=`(Timestamp=ymd_hms(Timestamp),
Date=ymd(Date),
SN=as.factor(SN))]
a[SN==c("2110000001","2110000002"),c("Timestamp","Date","Time","SN","A.Ms.Watt","Pac"),with=FALSE]
我得到这个输出:
> a[SN==c("2110000001","2110000002"),c("Timestamp","Date","Time","SN","A.Ms.Watt","Pac"),with=FALSE]
Timestamp Date Time SN A.Ms.Watt Pac
1: 2013-10-01 12:00:00 2013-10-01 12:00:00 2110000001 10723.0 13544.5
2: 2013-10-01 12:00:00 2013-10-01 12:00:00 2110000002 3704.0 6860.0
3: 2013-10-01 12:10:00 2013-10-01 12:10:00 2110000001 11278.5 14127.5
4: 2013-10-01 12:10:00 2013-10-01 12:10:00 2110000002 3952.0 7475.5
5: 2013-10-01 12:20:00 2013-10-01 12:20:00 2110000001 10279.5 12735.5
6: 2013-10-01 12:20:00 2013-10-01 12:20:00 2110000002 3929.0 7553.5
Warning messages:
1: In is.na(e1) | is.na(e2) :
longer object length is not a multiple of shorter object length
2: In `==.default`(SN, c("2110000001", "2110000002")) :
longer object length is not a multiple of shorter object length
不幸的是,我不太明白这些警告。但我每隔 12:xx:x5 间隔丢失一次数据(例如 12:00:05)。我可能做错了什么?