R 使用另一个data.table的派生值丰富data.table
假设以下数据表:R 使用另一个data.table的派生值丰富data.table,r,join,data.table,R,Join,Data.table,假设以下数据表: > valid_event_rows TTimeStamp DeviceIDI TimeOff AlarmGroup Alarmcode LogType idKey MailSend DownTime 1: 2011-09-15 11:46:39 4 2011-09-15 14:04:16 1 1111 0 791 1 138 mins
> valid_event_rows
TTimeStamp DeviceIDI TimeOff AlarmGroup Alarmcode LogType idKey MailSend DownTime
1: 2011-09-15 11:46:39 4 2011-09-15 14:04:16 1 1111 0 791 1 138 mins
2: 2011-09-15 11:47:14 4 2011-09-15 14:04:15 1 1015 2 793 0 137 mins
3: 2011-09-15 11:47:37 4 2011-09-15 14:04:18 1 1001 2 794 0 137 mins
4: 2011-09-15 11:57:34 4 2011-09-15 13:57:42 1 7111 2 795 0 120 mins
5: 2011-09-15 14:58:43 4 2011-09-15 17:59:03 1 7111 2 795 0 181 mins
...
> observed_failures
Group AlarmCode Description ErrorType
1: System 916 HW-profile not selected 1
2: System 1001 Manual stop 1
3: System 1003 Emergency switch activated 1
4: System 1004 External stop 0
5: System 1005 Availability - low wind W
...
我打算用一个新的列Frequency
扩展观察到的故障
表,该列包含有效事件行
表中相应报警代码
的计数()
我试图通过解析第一个表并将所有出现的情况计数到一个新的DTfailures\u分布中,然后将Frequency
列绑定到所需的表中,但没有成功
# Generate a High Level view root cause of observed failures
observed_failures <- event_categories[Number %in% event_data$Alarmcode]
observed_failures <- observed_failures[order(Number, decreasing = FALSE)]
# Build a DF with AlarmCode | Frequency
failures_distribution <- (count(sort(valid_event_rows$Alarmcode)))
# Bind the Frequency column to the table
failures_summary <- cbind(observed_failures,failures_distribution$freq) # BUG (!!!)
colnames(failures_summary)[5] <- "Frequency"
#生成观察到的故障根本原因的高级视图
观察到的\u故障您可以尝试一下dplyr
,计数有效的\u事件\u行中的报警代码,然后将这些频率加入观察到的\u故障:
library(dplyr)
frequencies <- count(valid_event_rows, AlarmCode)
failures_summary <- left_join(observed_failures, frequencies, on = 'AlarmCode')
库(dplyr)
频率如果你可以dput
我应该可以为你做这件事,而不是cbind
尝试做merge
。我几乎到处都能看到对dplyr的引用。我想我得学!再次感谢!