次のdata.tablesを仮定します。別のdata.tableの派生値を使用して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
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
...
私はvalid_event_rows
の表に、それぞれのAlarmcode
ためcount()
を含む新しい列Frequency
でobserved_failures
テーブルを拡張することを目指しています。
私が失敗した最初のテーブルを解析し、新しいDT failures_distribution
にすべてのオカレンスをカウントし、目的のテーブルに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"
event_categories
上のいくつかのイベントは、(設計によって)されているので、しかし、これは動作しませんでしたが、周波数マッピングにCBIND値を複製し、したがって、ネジ。
event_categories
で重複をソートして削除することで問題を解決できましたが、インラインで行うのが最も適切な方法を知りたいと思います。
私はあなたがobserved_failuresにleft_join
、その後、dplyr
にこれらの周波数をvalid_event_rowsでcount
alarmcodesを試してみるかもしれませんR.
データを 'dput'できたら、私はあなたのためにこれを行うことができるはずです –
' cbind'の代わりに 'merge'を実行してみてください。 – ytk