source("http://192.38.117.59/~linearpredictors/datafiles/readMelanoma.R") melanoma$timeint <- cut(melanoma$years, c(0, 2.5, 5, Inf), right = F, include.lower=T) melanoma$thickness <- cut(melanoma$thick, c(0,2,5,Inf), include.lower = T) ## number of cases in groups of time, thicknes and ulceration. with(melanoma, tapply(ifelse(dc != 2, 1, 0), list(ulc, thickness, timeint), sum) ) ## for each of the 3 time intervals, we calculate how many years each person ## contributes to the interval melanoma$t1 <- sapply(melanoma$years, function(x)min(x, 2.5)) melanoma$t2 <- ifelse(melanoma$years > 2.5, sapply(melanoma$years, function(x)min(x -2.5, 2.5)), 0) melanoma$t3 <- ifelse(melanoma$years > 5, melanoma$years - 5, 0) ## now calculate the total no of person years in the relevant groups tapply(melanoma$t1, list(melanoma$ulc, melanoma$thickness), sum) tapply(melanoma$t2, list(melanoma$ulc, melanoma$thickness), sum) tapply(melanoma$t3, list(melanoma$ulc, melanoma$thickness), sum)