1

My data is like this having 180 columns(column length are different) and length of column is very long-

1828    79595   219479  90102   1009
5936    114882  57685   6621    80823
27102   160335  51599   118987  
8912            5910        
4012                        

How to convert/arrange these multiple column into a single column like this-

1828
5936
27102
8912
4012
79595
114882
160335
219479
57685
51599
5910
90102
6621
118987
1009
80823

Using R-language because my data is so long that it can't able to fit in a excel sheet when converted to 1 column

xrxrxrxxr
  • 89
  • 1
  • 7
  • What format is your data? If matrix, change to vector using `c()` and then you can convert to matrix with 1 column, if you want. – yarnabrina May 19 '19 at 14:12

1 Answers1

0

Here's one solution, assuming your data live in a data.frame or data.table type object:

library(data.table)
dt <- data.table(matrix(rnorm(1000), ncol = 100))
melt(dt, measure.vars = 1:ncol(dt))
#>       variable        value
#>    1:       V1 -0.636795202
#>    2:       V1  0.726632131
#>    3:       V1 -1.657745472
#>    4:       V1 -0.011510918
#>    5:       V1  0.005966138
#>   ---                      
#>  996:     V100  0.698911628
#>  997:     V100 -0.612117248
#>  998:     V100 -0.738224511
#>  999:     V100  1.616901156
#> 1000:     V100 -1.673199333

Created on 2019-05-19 by the reprex package (v0.2.1)

Chase
  • 67,710
  • 18
  • 144
  • 161
  • but my data is not in form of matrix and the size of each column is different – xrxrxrxxr May 19 '19 at 14:43
  • If your data is a list, you can use `unlist`. – yarnabrina May 19 '19 at 15:32
  • @xrxrxrxxr - you need to provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and you'll get answers that are more directly relevant for your use case. As it stands, you're forcing people to make assumptions about your data. – Chase May 19 '19 at 16:27