This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how do merge several same columns as a rowname in R

Hello all

I have a matrix in R I want to know which code in R can merge same columns and convert them to rownames? Could anyone help me?

thanks in advance

rna-seq script code

What do you mean by "convert them to row names"?

Can you post an example of your current data, and the desired output data?

      V1    V2  V1  V2
1     A     2    A   3
2     B     4    B   5
3     C    6    C   7

for example, I want to convert a matrix above to something like that as below:

     V2   V2
A    2     3
B    4     5
C    6     7

Problem with this kind of example data is that it misleads (unless this is what is exactly required). For eg. output can be simply reproduced by following code:

> test2=data.frame(row.names=test[,1], test[,-c(1,3)])
> test2
  V2 V2.1
A  2    3
B  4    5
C  6    7

Hello lkianmehr!

We believe that this post does not fit the main topic of this site.

Please demonstrate how this is related to bioinformatics and not just a pure R question.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

I don't know why you always are closing my questions!

It is exactly related to bioinformatics and not just R!!!!

Because when everybody is doing some bioinformatic analysis with the order in pipeline, finally is needed to do with R. I got count files from htseq-count and they should be analysis by R, and that step was necessary to combine the lists of the count files for doing DESeq2 analysis!!!

It was closed because the data content isn't related to the problem as such. You may be using it for bioinformatics, but it, itself, is not a bioinformatics problem -- it is just a generic programming query. If it wasn't that your question was tagged with rna-seq there would be nothing to obviously connect it to a bioinformatics task.

I would be glad to explain to me what topic is the specifically bioinformatic problem and could you introduce me where can resolve such problems? I think just who are using such programs can resolve it not anyone else. my question is tagged with RNA-seq! anyway, this is not important that you closed my questions but maybe could resolve other's problem such me!

the Best!

The question was answered below anyway.

A specific bioinformatics problem might be, for example, a particular problem you encounter with DESeq2 itself.

In this case the question was just about manipulating a dataframe. The content of the dataframe isn't relevant - you could be working on one of the default R example data sets for instance, the problem would still be the same.

Those kinds of questions are better suited to StackExchange.

I was working with DESeq2 but before that dataframe of data was needed change. I wanted just to explain the problem with a small example like that!

thank you!

1 answer

Column names are unique in R@ lkianmehr

> test2=test[,!duplicated(t(test))]
> test2=data.frame(row.names=test2[,1],test2[,-1])
> test2
  V2 V2.1
A  2    3
B  4    5
C  6    7
> test
  V1 V2 V1.1 V2.1
1  A  2    A    3
2  B  4    B    5
3  C  6    C    7

Thank you very much. this code was efficient!

If an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted.
Upvote|Bookmark|Accept

Log in to answer this question.