人物期間データは、開始時刻と終了時刻が同じである呪文データの特殊なケースです。Timestamp
変数を複製し、最初start.time
と 2 番目の名前を変更することで、スペル データを取得しますstop.time
。
おそらく、引数list=c(Machine_id, event, TDV1, TDV2, TDV3, TDV4)
として使用してレコードを集約できます。by
で 1 回、 で 1 回、2 回処理を進めるFUN="min"
と、 と の共変量FUN="max"
の値が変更されていない呪文の開始時刻と終了時刻を見つけることができるはずですevent
。
I illustrate here with an example
## creating example data
p.df <- data.frame(scan(what=list(Id=0, timestamp=0, event="", work="", income=0)))
1 2000 S working 100
1 2001 S working 100
1 2002 M working 100
1 2003 M working 100
1 2004 M jobless 80
1 2005 M jobless 70
2 2000 S jobless 10
2 2001 S working 100
2 2002 S working 100
## leave previous line blank to end scan
p.df$start <- p.df$timestamp
p.df$end <- p.df$timestamp
p.df <- p.df[,-2] ## deleting timestamp variable
bylist <- list(id = p.df$Id, event=p.df$event,
work=p.df$work, income=p.df$income)
spell1 <- aggregate(p.df[,c("start","end")], by=bylist, FUN="min")
spell2 <- aggregate(p.df[,c("start","end")], by=bylist, FUN="max")
## reordering columns
spell <- spell1[,c(1,5,6,2,3,4)]
spell[,3] <- spell2[,6] ## taking end value from spell2
spell <- spell[order(spell$id,spell$start),] ## sorting rows
spell
## id start end event work income
## 5 1 2000 2001 S working 100
## 4 1 2002 2003 M working 100
## 3 1 2004 2004 M jobless 80
## 2 1 2005 2005 M jobless 70
## 1 2 2000 2000 S jobless 10
## 6 2 2001 2002 S working 100
お役に立てれば。