Skip to content
Prev 294631 / 398502 Next

How to Un-group a grouped data set?

newdats <- rbind(cbind(dats[rep(1:nrow(dats), dats$AEs), 1:2], 
  AEs=1), cbind(dats[rep(1:nrow(dats), dats$N-dats$AEs),1:2], 
  AEs=0))

But the data will not be in the order you specified unless you add

newdats <- newdats[order(newdats$Study, -newdats$TX, -newdats$AEs),]

and you may want to clean up the rownumbers with

rownames(newdats) <- 1:nrow(newdats)

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352