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.
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.
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.
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
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
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.