你是怎么做的,或者在r中的data.table包中ifelse

时间:2016-07-12 16:46:16

标签: r data.table

我有一个名为final的数据框:

dput(头(最终))

structure(list(Date = structure(c(1468268220, 1468269840, 1468268160, 
1468268700, 1468268760, 1468268940), class = c("POSIXct", "POSIXt"
), tzone = ""), Trans = c(1454L, 816L, 1144L, 2542L, 200L, 180L
), Cpu = c(64L, 40L, 56L, 61L, 16L, 11L), HeapUsage = c(57.0708814590398, 
80.9735869076328, 48.902594693305, 94.0288575990024, 69.2328919834884, 
82.9988047593942), upper = c(65.8548134294912, 42.4943251956111, 
51.6875408154387, 84.6919764584793, 23.1855269194862, 22.5880538495753
), lower = c(45.1948274687367, 24.2759551097326, 32.5602919366396, 
56.2960707237243, 8.75861931966005, 6.83960375748239), diff = c(1.85481342949123, 
2.49432519561113, 4.31245918456129, 23.6919764584793, 7.18552691948618, 
11.5880538495753)), .Names = c("Date", "Trans", "Cpu", "HeapUsage", 
"upper", "lower", "diff"), class = c("data.table", "data.frame"
), row.names = c(NA, -6L), .internal.selfref = <pointer: 0x0000000000170788>)

使用data.table包我需要查看每个日期的Trans值是否在上限和下限之内:

final<-final[,inside:=ifelse(Cpu>=lower || Cpu=<upper,1,0),by=c("Date")]

似乎没有使用OR任何想法

0 个答案:

没有答案