transpose rows and columns
3
0
Entering edit mode
9.6 years ago
kanwarjag ★ 1.2k

I have a dataset in excel/ txt file with 65 columns and 300000 rows. What will be the best way to switch columns and rows. It cannot be done in excel. I tried using R t() it also does not do the trick.

any suggestion?

Thanks

columns transpose rows • 7.4k views
ADD COMMENT
0
Entering edit mode

t() works on at least some data.frames (and indeed you can transpose sheets in excel, though I'd keep a 300K row sheet out of excel if I were you!). So what error messages to you get when you try to do this transposition?

ADD REPLY
0
Entering edit mode

Here is so far I have used-

dat<-read.delim(file="fILE_2_329515.txt",sep="\t", header=T)
dim(dat)

names(dat)

row.names(dat) <- dat[[1]]

t(dat)

write.table(dat,file="dat2.txt",sep="\t")

It is not changing the rows and columns and does not throw any error

ADD REPLY
1
Entering edit mode

You need to set the result when transposing.

dat <- t(dat)

will work.

ADD REPLY
1
Entering edit mode

My bad.

Thanks it worked

ADD REPLY
1
Entering edit mode
9.6 years ago
Dave Tang ▴ 210

I have a blog post containing Python and Perl code for carrying out a transpose on tab-delimited files. In the post, I also linked to a tool called datamash, which can carry out a transpose. Here's the URL: http://davetang.org/muse/2014/09/09/transpose-tool/.

ADD COMMENT
0
Entering edit mode
9.6 years ago

Here's an elegant and fast method in awk: http://stackoverflow.com/questions/1729824/transpose-a-file-in-bash

ADD COMMENT
0
Entering edit mode
9.6 years ago
5heikki 11k

This is a pretty neat coreutil-like tool for transposing csv and tsv

ADD COMMENT

Login before adding your answer.

Traffic: 1959 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