[R] For applying formula in rows

Bansal, Vikas vikas.bansal at kcl.ac.uk
Tue Jul 12 18:57:33 CEST 2011


Dear all,

I have a problem and it is very difficult for me to get a code.
I am reading a file(attached with this mail) using the code-

 df=read.table("summary.txt",fill=T,sep="",colClasses = "character",header=T)
and dataframe df is like this-

V1        V2      CaseA CaseC CaseG CaseT new
 10 135344109     0     0             1     0        12
 10 135344110     0     1             0     0         12
 10 135344111     0     0             1     0         12
 10 135344112     0     0             1     0          12
 10 135344113     0     0             1     0          12
 10 135344114     1     0             0     0          12
 10 135344115     1     0             0     0           12
 10 135344116     0     0             0     1           12
 10 135344117     0     1             0     0           12
 10 135344118     0     0             0     1            12

I want to apply a formula which is  (number/total)*new*2.
where number is in column caseA,G,C,T and total is sum of these 4 columns.I will explain with an example.the output of first row should be-

V1        V2      CaseA CaseC CaseG CaseT new
 10 135344109     0     0             24     0        12

because sum of 3rd,4th,5th and 6th column is 1 for first row.and for case A,C and T if we will apply above formula the answer will be zero (0/1)*12*2 which is equal to 0 but for Case G-
(1/1)*12*2 which is equal to 24.


Can you please help me.

 



Thanking you,
Warm Regards
Vikas Bansal
Msc Bioinformatics
Kings College London
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: summary.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110712/ec2a677e/attachment.txt>


More information about the R-help mailing list