How to get ncol = nrow?
2
0
Entering edit mode
14 months ago
Suha • 0

Hello,

I am trying to use DESeq2 and to create the matrix, I have to get the ncol of my data set to equal the nrow of the column information. I am unsure how to do this, so any help would be immensely appreciated.

enter image description here

enter image description here

DESeq2 • 784 views
ADD COMMENT
1
Entering edit mode

Set the row names to the values of column "X" and then drop column "X". Next time adjust your read.delim or whatever command to automatically set the first column to the row names.

ADD REPLY
1
Entering edit mode
14 months ago
Mark ★ 1.6k

Without your actual data, it's hard to assist. I think what you're asking is 'how do I rename the rows of my dataframe(s)'.

Taking the first table as an example, assuming it's called mydata then you can do this:

coldata = mydata[,2:3]
rownames(coldat) = mydata$x

First line selects columns 2 and 3, assigning to a new object called coldata. The second line renames the rows of coldata to the same values in x of mydata.

Do the same for the second dataframe. You can also do negative select to exclude the first column. eg mydata[ ,-1]. Not it's -1 (negative 1) to exclude the first column.

ADD COMMENT
1
Entering edit mode
14 months ago
fracarb8 ★ 1.7k

Assuming samples_counts is your count matrix and samples_meta is the metadata table, you can:

rownames(samples_counts) <- samples_counts$X
samples_counts$X <- NULL
# use names if samples_counts is a data.frame
samples_counts <- samples_counts[, which(colnames(samples_counts) %in% samples_meta$x)]

That should also take care of the order of the samples

ADD COMMENT

Login before adding your answer.

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