[R] how to compute when row length is different

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Tue Sep 14 16:37:50 CEST 2010


You need to line up the rows before you do the arithmetic.  Check out ?merge

"rasanpreet" <rasanpreet.kaur at gmail.com> wrote:

>
>hi guys..please help me with this
>i am working on two data frames
>one goes like this:
>DF1
>Sample_id RepairHours Denatured Dose ZeroMean FourtyFiveMean NinetyMean
>1     SDM071           0         1    B     60.5           19.0       45.0
>2     SDM071           1         1    B     46.0           23.0       42.5
>3     SDM071           2         1    B     52.5           24.0       40.0
>4     SDM071           3         1    B     42.0           21.5       45.0
>5     SDM053           0         1    B     66.5           28.5       56.5
>6     SDM053           1         1    B     47.0           29.0       47.5
>7     SDM053           2         1    B     52.0           31.0       44.0
>8     SDM053           3         1    B     36.0           34.0       41.5
>9     SDM059           0         1    B     47.5           41.5       29.0
>10    SDM059           1         1    B     47.0           36.0       35.0
>11    SDM059           2         1    B     41.5           42.0       32.5
>12    SDM059           3         1    B     46.5           41.5       32.0
>
>
>and the other one:
>DF2
>SampleId RepairHours Denatured Dose_uM Day_0_Read1 Day_0_Read2 Day_45_Read1
>8    SDM071           0         1       C         124         120         
>108
>9    SDM071           0         1      25         123         128          
>77
>10   SDM071           0         1      50         132         138          
>79
>11   SDM071           0         1     100         118         116          
>68
>12   SDM071           0         1     200         125         146          
>73
>20   SDM071           1         1       C         113         117         
>113
>21   SDM071           1         1      25         108         115         
>132
>22   SDM071           1         1      50         105          96          
>94
>23   SDM071           1         1     100         101         101          
>88
>24   SDM071           1         1     200         114         106          
>89
>32   SDM071           2         1       C         143         136         
>109
>33   SDM071           2         1      25         126         147         
>110
>34   SDM071           2         1      50         109         122         
>107
>35   SDM071           2         1     100         114         118          
>89
>36   SDM071           2         1     200         118         128          
>88
>44   SDM071           3         1       C         103         111         
>116
>45   SDM071           3         1      25         108         105         
>115
>46   SDM071           3         1      50         118          99          
>88
>47   SDM071           3         1     100          98         103         
>105
>48   SDM071           3         1     200         112         105          
>96
>56   SDM053           0         1       C         214         208         
>158
>57   SDM053           0         1      25         159         214         
>178
>58   SDM053           0         1      50         170         169         
>112
>59   SDM053           0         1     100         149         158         
>124
>60   SDM053           0         1     200         201         171         
>115
>68   SDM053           1         1       C         149         166         
>120
>69   SDM053           1         1      25         145         134         
>118
>70   SDM053           1         1      50         159         169         
>130
>71   SDM053           1         1     100         113         126         
>110
>72   SDM053           1         1     200         118         112         
>120
>
>
>these are just part of the frames......
>i have to subtract the first five values of dataframe2 from one value from
>dataframe1
>eg: subtract<-DF2$Day_0_Read1-DF1$ ZeroMean
>
>
>if u notice the repair hours in both have to match...along with their id's.
>i have tried this 
>zeroday_subtract1=DF1$Day_0_Read1 - DF2[DF1$RepairHours,]$ZeroMean
>but it dosent work
>
>
>please help me with this...i know its basic but i needhelp  
>thx in advance
>
>
>-- 
>View this message in context: http://r.789695.n4.nabble.com/how-to-compute-when-row-length-is-different-tp2538930p2538930.html
>Sent from the R help mailing list archive at Nabble.com.
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list