R loop for question
2
0
Entering edit mode
8.9 years ago
bgraphit ▴ 20

I need some help figuring out how to make a loop in R.

I have a data frame named x x dimensions are 12773 rows and 86 columns.

column 1 has gene name, columns 2-85 counts for my different libraries, and 86 column is the mean of the library counts in columns 2-85 for each gene name.

I need help making a loop that would create a data frame or matrix output with the values of residuals of mean:

count - mean for each library and gene.

Expected output would be a new data frame y with column 1 gene names from data frame x which is column 1. In addition to having columns 2-85 with values that correspond to count-mean

Data frame x:

gene accepted_hits_x1.bam   accepted_hits_x2.bam   ...   mean
AARS2      12                   6                             6

DATA FRAME: y

         gene       accepted_hits_x1.bam      accepted_hits_x1.bam   ....  
 1      AARS1          -6                            0
R • 2.0k views
ADD COMMENT
3
Entering edit mode
8.9 years ago
Michael 54k

No for Loops!

x[,2:85] - x[,86]
ADD COMMENT
0
Entering edit mode

Yet how to add the gene column from x to this data frame

ADD REPLY
2
Entering edit mode
8.9 years ago
h.mon 35k

Just detailing Michael Dondrup answer:

y <- x[,2:85] - x[,86]
y <- cbind( x[,1], y )
ADD COMMENT
0
Entering edit mode

Thank you! exactly what I was going to ask! :) about cbind

Thanks guys!

ADD REPLY

Login before adding your answer.

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