Skip to content
Prev 361740 / 398503 Next

inverse table

Hi Patrizio,

maybe there is a more efficient way, but you can loop over rows and columns
like this

ab.recon <- data.frame()

ddd.rownames <- rownames(ddd)
ddd.colnames <- colnames(ddd)

for(cur.row in ddd.rownames){
  for(cur.col in ddd.colnames){
    times.found <- ddd[cur.row, cur.col]
    tmp.df <- data.frame(a = rep(cur.row, times.found),
                         b = rep(cur.col, times.found))
    ab.recon <- rbind(ab.recon, tmp.df)
  }
}

Hope this helps
Ulrik

On Wed, 15 Jun 2016 at 18:12 Patrizio Frederic <frederic.patrizio at gmail.com>
wrote: