Question: transpose rows and columns
0
gravatar for kanwarjag
5.0 years ago by
kanwarjag1.0k
United States
kanwarjag1.0k wrote:

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 rows transpose • 4.7k views
ADD COMMENTlink modified 5.0 years ago by 5heikki8.7k • written 5.0 years ago by kanwarjag1.0k

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 REPLYlink written 5.0 years ago by David W4.7k

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 REPLYlink written 5.0 years ago by kanwarjag1.0k
1

You need to set the result when transponsing. 

dat <- t(dat)

will work. 

ADD REPLYlink written 5.0 years ago by Danielk590
1

My bad.

Thanks it worked

ADD REPLYlink written 5.0 years ago by kanwarjag1.0k
1
gravatar for Dave Tang
5.0 years ago by
Dave Tang190
Australia
Dave Tang190 wrote:

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 COMMENTlink written 5.0 years ago by Dave Tang190
0
gravatar for Alex Reynolds
5.0 years ago by
Alex Reynolds29k
Seattle, WA USA
Alex Reynolds29k wrote:

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

ADD COMMENTlink written 5.0 years ago by Alex Reynolds29k
0
gravatar for 5heikki
5.0 years ago by
5heikki8.7k
Finland
5heikki8.7k wrote:

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

ADD COMMENTlink written 5.0 years ago by 5heikki8.7k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1823 users visited in the last hour