Skip to content
Prev 316476 / 398506 Next

I think you misunderstood my explantation.

Hi,

Your dataset had already some missing values.? So, I need to subset only those rows that are not missing.
!is.na(temp$ACTIVE_KWH)
# [1]? TRUE? TRUE? TRUE FALSE? TRUE FALSE FALSE? TRUE? TRUE? TRUE? TRUE FALSE
#[13]? TRUE? TRUE? TRUE
temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)]
#[1] 1201.9 1202.2 1202.8 1203.9?? 12.0 1206.0 1206.3 1206.5 1207.3 1207.9
#[11] 1208.4

?diff() will get the differences between successive values
diff(temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)])
?#[1]???? 0.3???? 0.6???? 1.1 -1191.9? 1194.0???? 0.3???? 0.2???? 0.8???? 0.6
#[10]???? 0.5

#Here, the length is 1 less than the previous case as the first value is removed.
?diff(temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)])<0
# [1] FALSE FALSE FALSE? TRUE FALSE FALSE FALSE FALSE FALSE FALSE

#Added `FALSE` at the beginning to make the length equal to subset data
indx<- c(FALSE,diff(temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)])<0)
indx 
#[1] FALSE FALSE FALSE FALSE? TRUE FALSE FALSE FALSE FALSE FALSE FALSE

#Using this index, further subset the already subset data for differences of values <0
?temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)][indx]
#[1] 12
temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)][indx]<- NA #changed to NA

#Similarly for REACTIVE_KWH
Hope this helps.
A.K.
Message-ID: <1359546825.70500.YahooMailNeo@web142605.mail.bf1.yahoo.com>
In-Reply-To: <1e1da6db68884f1081c035d367ddae16@tweb04.nm.nhnsystem.com>