Biostar Beta. Not for public use.
transpose rows and columns
0
Entering edit mode
15 months ago
kanwarjag • 960
United States

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

ADD COMMENTlink
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 REPLYlink
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 REPLYlink
1
Entering edit mode

You need to set the result when transponsing.

dat <- t(dat)

will work.

ADD REPLYlink
1
Entering edit mode

My bad.

Thanks it worked

ADD REPLYlink
1
Entering edit mode
16 months ago
Dave Tang • 180
Australia

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
0
Entering edit mode
16 months ago
Seattle, WA USA

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

ADD COMMENTlink
0
Entering edit mode
14 months ago
5heikki 8.4k
Finland

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

ADD COMMENTlink

Login before adding your answer.

Similar Posts
Loading Similar Posts
Powered by the version 2.3