Arrange multiple column into a single column using R-language
0
0
Entering edit mode
5.5 years ago
xxxxxxxx ▴ 20

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

R csv • 939 views
ADD COMMENT
2
Entering edit mode

with op data:

> library(tidyr)
> df=read.csv("test.txt", strip.white = T, stringsAsFactors = F, sep="\t", header = F)
> df
     V1     V2     V3     V4    V5
1  1828  79595 219479  90102  1009
2  5936 114882  57685   6621 80823
3 27102 160335  51599 118987    NA
4  8912   5910     NA     NA    NA
5  4012     NA     NA     NA    NA
> na.omit(as.data.frame(gather(df)[,2]))
   gather(df)[, 2]
1             1828
2             5936
3            27102
4             8912
5             4012
6            79595
7           114882
8           160335
9             5910
11          219479
12           57685
13           51599
16           90102
17            6621
18          118987
21            1009
22           80823
>
ADD REPLY
1
Entering edit mode

Or (saving test.txt as a text file)

pp<-read.table("test.txt",fill=T,strip.white=T,header=F)
as.data.frame(na.omit(unlist(pp)))
ADD REPLY

Login before adding your answer.

Traffic: 1727 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6