Data examples
I have 100 rows of patient data stored in an object example. For each patient, we know which of the five possible hospitals with which they were treated, the period of time during which they were treated, and the number of lymph nodes in them.
set.seed(50)
example <- data.frame(
Hospital = sample(as.factor(c("Hospital 1", "Hospital 2", "Hospital 3", "Hospital 4", "Hospital 5")), size = 100, replace = TRUE),
Time = sample(as.factor(c("2000-2002", "2003-2005", "2006-2008")), size = 100, replace = TRUE),
Nodes = sample(20:100, size = 100, replace = TRUE))
I know that I can see summary statistics on the number of lymph nodes, for example ... (Note that I added "n" to the right column on the right, not sure if there is a more eloquent way to do this.)
cbind(do.call(rbind, by(example$Nodes, example$Hospital, summary)), table(example$Hospital, useNA = "no"))
Min. 1st Qu. Median Mean 3rd Qu. Max.
Hospital 1 20 34.25 54.0 55.55 77.75 90 22
Hospital 2 22 38.75 60.5 56.25 71.75 94 20
Hospital 3 22 37.00 51.0 57.12 81.00 96 17
Hospital 4 25 39.75 55.5 57.11 72.25 97 28
Hospital 5 26 42.00 50.0 57.00 77.00 99 13
Similarly, I can view them over a period of time as follows:
cbind(do.call(rbind, by(example$Nodes, example$Time, summary)), table(example$Time, useNA = "no"))
Min. 1st Qu. Median Mean 3rd Qu. Max.
2000-2002 20 40.00 57.0 58.84 77 97 37
2003-2005 20 33.75 45.5 52.94 78 99 36
2006-2008 23 39.50 61.0 58.33 72 98 27
Question
, , . , . , xtabs() ftable(), , . , ftable(example) , , , , . !
# 1 -
, , , . , , , ( , ):
Nodes
Min. 1st Qu. Median Mean 3rd Qu. Max. n
Hospital Time
Hospital 1 2000-2002
2003-2005
2006-2008
Hospital 2 2000-2002
2003-2005
2006-2008
....and so forth....