How to Convert Table Into Columns R -


how convert datatables columns, example:

  ab cd ef jk lm x 6  0  5  0  0 y 0  7  0  0  0 z 0  0  8  0  0  0  0  0  9  0 b 0  0  0  6  10 

to

      v1   v2     x    ab   6   x    ef   5  y    cd   7   z    ef   8     jk   9  b    lm   10  b    jk   6 

one option convert 'data.frame' 'matrix', melt it, , subset 'value' not '0'.

 library(reshape2)  subset(melt(as.matrix(df1)), value!=0) 

or

 library(dplyr)  library(tidyr)  add_rownames(df1, 'rn') %>%           gather(v1, v2, -rn) %>%           filter(v2!=0)  

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -