Rafe's problem

d = data.frame(doc = c(1,2,3,2,2,3,4,6,5,5), 
   prepost= c(0,0,1,1,1,0,0,1,0,1))
d =d[order(d$doc),]

uu = function(u){
  u = unique(u)
  if (length(u)==2){ "III"
  } else{if (u==1) "II" else "I"}
}

p =  tapply(d$prepost, d$doc, FUN=uu)
d$cl = p[as.character(d$doc)]
# OR
d$cl =  tapply(d$prepost, d$doc, FUN=uu)[as.character(d$doc)]

# if missing values
d = data.frame(doc = c(1,2,1,3,2,2,3,3,4,6,5,5), 
   prepost= c(0,0,1,1,1,NA,0,0,1,NA,,0,1))

p = with(subset(d, subset=!is.na(prepost)),
   tapply(prepost, doc, FUN=uu))
d$cl = p[as.character(d$doc)]

This topic: Main > WebHome > Seminars > RClinic > DMEx1
Topic revision: 21 Nov 2006, TheresaScott
 
This site is powered by FoswikiCopyright © 2013-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback