Question: R loop for question
0
gravatar for bgraphit
5.4 years ago by
bgraphit20
United States
bgraphit20 wrote:

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
for loops R • 1.4k views
ADD COMMENTlink modified 5.4 years ago by h.mon31k • written 5.4 years ago by bgraphit20
3
gravatar for Michael Dondrup
5.4 years ago by
Bergen, Norway
Michael Dondrup47k wrote:

No for Loops!

x[,2:85] - x[,86]

 

ADD COMMENTlink written 5.4 years ago by Michael Dondrup47k
Yet how to add the gene column from x to this data frame
ADD REPLYlink written 5.4 years ago by bgraphit20
2
gravatar for h.mon
5.4 years ago by
h.mon31k
Brazil
h.mon31k wrote:

just detailing Michael Dondrup answer:

y <- x[,2:85] - x[,86]

y <- cbind( x[,1], y )

 

ADD COMMENTlink written 5.4 years ago by h.mon31k

thank you! exactly what i was going to ask! :) about cbind

thanks guys!

 

ADD REPLYlink written 5.4 years ago by bgraphit20
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1793 users visited in the last hour