[R] how to compute when row length is different

2010-09-14 Thread rasanpreet

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 1B 60.5   19.0   45.0
2 SDM071   1 1B 46.0   23.0   42.5
3 SDM071   2 1B 52.5   24.0   40.0
4 SDM071   3 1B 42.0   21.5   45.0
5 SDM053   0 1B 66.5   28.5   56.5
6 SDM053   1 1B 47.0   29.0   47.5
7 SDM053   2 1B 52.0   31.0   44.0
8 SDM053   3 1B 36.0   34.0   41.5
9 SDM059   0 1B 47.5   41.5   29.0
10SDM059   1 1B 47.0   36.0   35.0
11SDM059   2 1B 41.5   42.0   32.5
12SDM059   3 1B 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
8SDM071   0 1   C 124 120 
108
9SDM071   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@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.


Re: [R] how to compute when row length is different

2010-09-14 Thread Nikhil Kaza


DF3 - merge(DF1, DF2, by=c(Sample_id, RepairHours), all.y=T)

DF3$subtract - DF3$Day_0_Read1-DF3$ ZeroMean


Nikhil Kaza
Asst. Professor,
City and Regional Planning
University of North Carolina

nikhil.l...@gmail.com

On Sep 14, 2010, at 8:38 AM, rasanpreet 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 1B 60.5
19.0   45.0
2 SDM071   1 1B 46.0
23.0   42.5
3 SDM071   2 1B 52.5
24.0   40.0
4 SDM071   3 1B 42.0
21.5   45.0
5 SDM053   0 1B 66.5
28.5   56.5
6 SDM053   1 1B 47.0
29.0   47.5
7 SDM053   2 1B 52.0
31.0   44.0
8 SDM053   3 1B 36.0
34.0   41.5
9 SDM059   0 1B 47.5
41.5   29.0
10SDM059   1 1B 47.0
36.0   35.0
11SDM059   2 1B 41.5
42.0   32.5
12SDM059   3 1B 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

8SDM071   0 1   C 124 120
108
9SDM071   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@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.


__
R-help@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.


Re: [R] how to compute when row length is different

2010-09-14 Thread Dennis Murphy
Hi:

Just to be different, here's a data.table solution:

library(data.table)

# It's always a good idea to have your merge key variables match in each
data frame/table
names(DF1)[1] - 'SampleId'
dt1 - data.table(DF1, key = 'SampleId, RepairHours')
dt2 - data.table(DF2, key = 'SampleId, RepairHours')
dt3 - merge(dt1, dt2)
 dim(dt3)
[1] 30 12 # check
# Do the subtraction
dt3$diff - with(dt3, Day_0_Read1 - ZeroMean)

If you want to perform operations between two data frames/tables, you need
to merge the data first before you can perform the calculation(s). Dr.
Kaza's solution works if you change the ID variable name first in DF1 the
way I did and substitute SampleId for Sample_id in his code, or if you
change the ID variable in DF2 to Sample_id and use his code as is.

HTH,
Dennis

On Tue, Sep 14, 2010 at 5:38 AM, rasanpreet rasanpreet.k...@gmail.comwrote:


 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 1B 60.5   19.0   45.0
 2 SDM071   1 1B 46.0   23.0   42.5
 3 SDM071   2 1B 52.5   24.0   40.0
 4 SDM071   3 1B 42.0   21.5   45.0
 5 SDM053   0 1B 66.5   28.5   56.5
 6 SDM053   1 1B 47.0   29.0   47.5
 7 SDM053   2 1B 52.0   31.0   44.0
 8 SDM053   3 1B 36.0   34.0   41.5
 9 SDM059   0 1B 47.5   41.5   29.0
 10SDM059   1 1B 47.0   36.0   35.0
 11SDM059   2 1B 41.5   42.0   32.5
 12SDM059   3 1B 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
 8SDM071   0 1   C 124 120
 108
 9SDM071   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@r-project.org mailing list
 

Re: [R] how to compute when row length is different

2010-09-14 Thread Jeff Newmiller
You need to line up the rows before you do the arithmetic.  Check out ?merge

rasanpreet rasanpreet.k...@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 1B 60.5   19.0   45.0
2 SDM071   1 1B 46.0   23.0   42.5
3 SDM071   2 1B 52.5   24.0   40.0
4 SDM071   3 1B 42.0   21.5   45.0
5 SDM053   0 1B 66.5   28.5   56.5
6 SDM053   1 1B 47.0   29.0   47.5
7 SDM053   2 1B 52.0   31.0   44.0
8 SDM053   3 1B 36.0   34.0   41.5
9 SDM059   0 1B 47.5   41.5   29.0
10SDM059   1 1B 47.0   36.0   35.0
11SDM059   2 1B 41.5   42.0   32.5
12SDM059   3 1B 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
8SDM071   0 1   C 124 120 
108
9SDM071   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@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 NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)  

Re: [R] how to compute when row length is different

2010-09-14 Thread rasanpreet

thank you so much Dennis...i got it[?]

On Tue, Sep 14, 2010 at 7:01 AM, Dennis Murphy [via R] 
ml-node+2539020-1932381782-160...@n4.nabble.comml-node%2b2539020-1932381782-160...@n4.nabble.com
 wrote:

 Hi:

 Just to be different, here's a data.table solution:

 library(data.table)

 # It's always a good idea to have your merge key variables match in each
 data frame/table
 names(DF1)[1] - 'SampleId'
 dt1 - data.table(DF1, key = 'SampleId, RepairHours')
 dt2 - data.table(DF2, key = 'SampleId, RepairHours')
 dt3 - merge(dt1, dt2)
  dim(dt3)
 [1] 30 12 # check
 # Do the subtraction
 dt3$diff - with(dt3, Day_0_Read1 - ZeroMean)

 If you want to perform operations between two data frames/tables, you need
 to merge the data first before you can perform the calculation(s). Dr.
 Kaza's solution works if you change the ID variable name first in DF1 the
 way I did and substitute SampleId for Sample_id in his code, or if you
 change the ID variable in DF2 to Sample_id and use his code as is.

 HTH,
 Dennis

 On Tue, Sep 14, 2010 at 5:38 AM, rasanpreet [hidden 
 email]http://user/SendEmail.jtp?type=nodenode=2539020i=0wrote:


 
  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 1B 60.5   19.0
 45.0
  2 SDM071   1 1B 46.0   23.0
 42.5
  3 SDM071   2 1B 52.5   24.0
 40.0
  4 SDM071   3 1B 42.0   21.5
 45.0
  5 SDM053   0 1B 66.5   28.5
 56.5
  6 SDM053   1 1B 47.0   29.0
 47.5
  7 SDM053   2 1B 52.0   31.0
 44.0
  8 SDM053   3 1B 36.0   34.0
 41.5
  9 SDM059   0 1B 47.5   41.5
 29.0
  10SDM059   1 1B 47.0   36.0
 35.0
  11SDM059   2 1B 41.5   42.0
 32.5
  12SDM059   3 1B 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
  8SDM071   0 1   C 124 120
  108
  9SDM071   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: