s-news
[Top] [All Lists]

Re: Alternative to reShape

To: Bert Jacobs <b.jacobs@pandora.be>, s-news@lists.biostat.wustl.edu
Subject: Re: Alternative to reShape
From: "Richard M. Heiberger" <rmh@temple.edu>
Date: Tue, 18 Oct 2005 18:56:01 -0400
reshape <- function(group, values) {
  t2 <- split(values, group)
  t3 <- max(sapply(t2, length))
  for (i in 1:length(t2)) length(t2[[i]]) <- t3
  as.data.frame(t2)
}

tmp <- data.frame(c1=rep(c("A","B","C"),c(2,3,1)),
                  c2=paste("A",c(1,2,2,3,4,1),sep=""))
tmp
reshape(tmp$c1, tmp$c2)

<Prev in Thread] Current Thread [Next in Thread>