Displaying 1 result from an estimated 1 matches for "lastind".
Did you mean:
lasting
2011 Aug 31
1
formatting a 6 million row data set; creating a censoring variable
...;data.frame", row.names = c(NA, -20L))
# here is plyr solution with idata.frame
library(plyr)
imyData <- idata.frame(myData)
timeData <- idata.frame(ddply(imyData, .(id,mygroup), summarize,
mytime = length(mygroup)))
makeCensor <- function(x) {
myvec <- rep(0,length(x))
lastInd <- length(myvec)
myvec[lastInd] = 1
myvec
}
plyrSolution <- ddply(timeData, "id", transform, censor = makeCensor(mygroup))
# here is a data table solution
# use makeCensor function from above
library(data.table)
mydt <- data.table(myData)
setkey(mydt,id,mygroup)
timeD...