[R] merging multiple data frames

2010-09-23 Thread rasanpreet

hi guys
i have multiple data frames which i want to  merge.
there are four of them..eg
pdf

SampleID UVDose_J RepairHours   Day_0  Day_45  Day_90
1SDM001  1.0   3 485.612 465.142 490.873
2SDM001  1.0   3 503.658 457.863 487.783
3SDM001  1.0   2 533.193 451.044 456.973
4SDM001  1.0   2 538.334 452.887 474.915
5SDM001  1.0   1 526.034 481.123 477.801
6SDM001  1.0   1 546.543 472.322 481.546
7SDM001  1.0   0  NA  NA  NA
8SDM001  1.0   0  NA  NA  NA
9SDM001  0.5   3 432.134 457.245 497.975
10   SDM001  0.5   3 432.605 450.184 489.468
11   SDM001  0.5   2 450.335 496.520 488.784
12   SDM001  0.5   2 439.590 474.371 470.182
13   SDM001  0.5   1 510.480 489.561 525.029
14   SDM001  0.5   1 487.934 467.258 488.784
15   SDM001  0.5   0  NA  NA  NA
16   SDM001  0.5   0  NA  NA  NA
20   SDM002  1.0   3 465.549 528.715 501.374
21   SDM002  1.0   3 458.168 505.480 489.244
22   SDM002  1.0   2 447.317 464.009 478.058
23   SDM002  1.0   2 452.020 438.446 470.996
24   SDM002  1.0   1 441.718 458.760 499.221
25   SDM002  1.0   1 447.017 402.616 548.797
26   SDM002  1.0   0  NA  NA  NA
27   SDM002  1.0   0  NA  NA  NA
28   SDM002  0.5   3 421.409 448.870 476.392
29   SDM002  0.5   3 404.089 446.413 477.080
30   SDM002  0.5   2 399.775 432.678 465.015
31   SDM002  0.5   2 427.157 443.418 477.048
32   SDM002  0.5   1 389.674 449.353 482.264
33   SDM002  0.5   1 418.147 455.983 495.486
34   SDM002  0.5   0  NA  NA  NA
35   SDM002  0.5   0  NA  NA  NA
39   SDM005  1.0   3 579.836 441.040 476.382
40   SDM005  1.0   3 578.525 443.875 472.867
41   SDM005  1.0   2 564.266 432.116 469.416
42   SDM005  1.0   2 571.045 447.658 458.233
43   SDM005  1.0   1 564.664 427.673 524.122
44   SDM005  1.0   1 568.182 458.039 477.237
45   SDM005  1.0   0  NA  NA  NA
46   SDM005  1.0   0  NA  NA  NA
47   SDM005  0.5   3 556.534 424.786 501.658
48   SDM005  0.5   3 474.027 441.418 507.635
49   SDM005  0.5   2 481.355 430.346 468.021
50   SDM005  0.5   2 478.922 466.933 471.025
51   SDM005  0.5   1 505.539 937.759 460.985
52   SDM005  0.5   1 497.913 457.932 493.152
53   SDM005  0.5   0  NA  NA  NA
54   SDM005  0.5   0  NA  NA  NA
58   SDM006  1.0   3 589.164 459.578 509.565
59   SDM006  1.0   3 608.477 480.233 519.785
60   SDM006  1.0   2 598.354 449.266 487.058
61   SDM006  1.0   2 617.823 456.908 507.467
62   SDM006  1.0   1 566.477 500.189 526.744
63   SDM006  1.0   1 622.170 462.463 550.675
64   SDM006  1.0   0  NA  NA  NA
65   SDM006  1.0   0  NA  NA  NA
66   SDM006  0.5   3 546.472 457.880 468.129
67   SDM006  0.5   3 525.069 444.575 505.154
68   SDM006  0.5   2 569.068 446.196 473.739
69   SDM006  0.5   2 534.205 470.366 476.570

bdf
SampleID UVDose_J RepairHoursDay_0   Day_45  Day_90
17SDM001  0.5   B  88.6145 388.3575 198.467
36SDM002  0.5   B 100.0760 384.9505 234.740
55SDM005  0.5   B 121.9595 300.3650 241.832
74SDM006  0.5   B 174.7005 378.3435 291.272
93SDM007  0.5   B 319.7750 335.4390 110.306
112   SDM008  0.5   B 292.8400 323.0370 172.615
131   SDM010  0.5   B 112.0225 281.0390 562.459
150   SDM011  0.5   B 125.0440 331.4650 230.026
169   SDM012  0.5   B 229.1310 264.5580 234.231
188   SDM013  0.5   B 212.9690 524.0240 420.211
207   SDM014  0.5   B 366.3350 225.0610 203.588
226   SDM016  0.5   B 305.6080 381.5770 155.052
245   SDM017  0.5   B 223.6260 281.7830 182.374
264   SDM018  0.5   B 200.7720 401.6350 193.573
283   SDM019  0.5   B 164.2360 156.9960 175.896
302   SDM023  0.5   B 198.8900 210.0600 215.629
321   SDM024  0.5   B 351.8460 100.0980 185.388
340   SDM026  0.5   B 190.4560 132.8970 160.213
359   SDM028  0.5   B 252.9760 158.2910 120.425
378   SDM029  0.5   B 411.0690 134.1060 138.528

tdf
SampleID UVDose_J RepairHours Day_0   Day_45  Day_90
19SDM001  0.5   T  642.3255 579.6635 537.581
38SDM002  0.5   T  531.2000 

Re: [R] merging multiple data frames

2010-09-23 Thread Steve Lianoglou
Hi,

On Thu, Sep 23, 2010 at 9:04 AM, rasanpreet rasanpreet.k...@gmail.com wrote:

 hi guys
 i have multiple data frames which i want to  merge.
 there are four of them..eg

Can you provide a (correct) example of what you want your merged
data.frame to look like?
What column do you want to use in your data.frame to merge against?
I'm guessing SampleID(?), but then again, these aren't unique in your
`pdf` data.frame. For instance, what would the row for SDM001 look
like in your merged data.frame?

-steve

 pdf

 SampleID UVDose_J RepairHours   Day_0  Day_45  Day_90
 1    SDM001      1.0           3 485.612 465.142 490.873
 2    SDM001      1.0           3 503.658 457.863 487.783
 3    SDM001      1.0           2 533.193 451.044 456.973
 4    SDM001      1.0           2 538.334 452.887 474.915
 5    SDM001      1.0           1 526.034 481.123 477.801
 6    SDM001      1.0           1 546.543 472.322 481.546
 7    SDM001      1.0           0      NA      NA      NA
 8    SDM001      1.0           0      NA      NA      NA
 9    SDM001      0.5           3 432.134 457.245 497.975
 10   SDM001      0.5           3 432.605 450.184 489.468
 11   SDM001      0.5           2 450.335 496.520 488.784
 12   SDM001      0.5           2 439.590 474.371 470.182
 13   SDM001      0.5           1 510.480 489.561 525.029
 14   SDM001      0.5           1 487.934 467.258 488.784
 15   SDM001      0.5           0      NA      NA      NA
 16   SDM001      0.5           0      NA      NA      NA
 20   SDM002      1.0           3 465.549 528.715 501.374
 21   SDM002      1.0           3 458.168 505.480 489.244
 22   SDM002      1.0           2 447.317 464.009 478.058
 23   SDM002      1.0           2 452.020 438.446 470.996
 24   SDM002      1.0           1 441.718 458.760 499.221
 25   SDM002      1.0           1 447.017 402.616 548.797
 26   SDM002      1.0           0      NA      NA      NA
 27   SDM002      1.0           0      NA      NA      NA
 28   SDM002      0.5           3 421.409 448.870 476.392
 29   SDM002      0.5           3 404.089 446.413 477.080
 30   SDM002      0.5           2 399.775 432.678 465.015
 31   SDM002      0.5           2 427.157 443.418 477.048
 32   SDM002      0.5           1 389.674 449.353 482.264
 33   SDM002      0.5           1 418.147 455.983 495.486
 34   SDM002      0.5           0      NA      NA      NA
 35   SDM002      0.5           0      NA      NA      NA
 39   SDM005      1.0           3 579.836 441.040 476.382
 40   SDM005      1.0           3 578.525 443.875 472.867
 41   SDM005      1.0           2 564.266 432.116 469.416
 42   SDM005      1.0           2 571.045 447.658 458.233
 43   SDM005      1.0           1 564.664 427.673 524.122
 44   SDM005      1.0           1 568.182 458.039 477.237
 45   SDM005      1.0           0      NA      NA      NA
 46   SDM005      1.0           0      NA      NA      NA
 47   SDM005      0.5           3 556.534 424.786 501.658
 48   SDM005      0.5           3 474.027 441.418 507.635
 49   SDM005      0.5           2 481.355 430.346 468.021
 50   SDM005      0.5           2 478.922 466.933 471.025
 51   SDM005      0.5           1 505.539 937.759 460.985
 52   SDM005      0.5           1 497.913 457.932 493.152
 53   SDM005      0.5           0      NA      NA      NA
 54   SDM005      0.5           0      NA      NA      NA
 58   SDM006      1.0           3 589.164 459.578 509.565
 59   SDM006      1.0           3 608.477 480.233 519.785
 60   SDM006      1.0           2 598.354 449.266 487.058
 61   SDM006      1.0           2 617.823 456.908 507.467
 62   SDM006      1.0           1 566.477 500.189 526.744
 63   SDM006      1.0           1 622.170 462.463 550.675
 64   SDM006      1.0           0      NA      NA      NA
 65   SDM006      1.0           0      NA      NA      NA
 66   SDM006      0.5           3 546.472 457.880 468.129
 67   SDM006      0.5           3 525.069 444.575 505.154
 68   SDM006      0.5           2 569.068 446.196 473.739
 69   SDM006      0.5           2 534.205 470.366 476.570

 bdf
 SampleID UVDose_J RepairHours    Day_0   Day_45  Day_90
 17    SDM001      0.5           B  88.6145 388.3575 198.467
 36    SDM002      0.5           B 100.0760 384.9505 234.740
 55    SDM005      0.5           B 121.9595 300.3650 241.832
 74    SDM006      0.5           B 174.7005 378.3435 291.272
 93    SDM007      0.5           B 319.7750 335.4390 110.306
 112   SDM008      0.5           B 292.8400 323.0370 172.615
 131   SDM010      0.5           B 112.0225 281.0390 562.459
 150   SDM011      0.5           B 125.0440 331.4650 230.026
 169   SDM012      0.5           B 229.1310 264.5580 234.231
 188   SDM013      0.5           B 212.9690 524.0240 420.211
 207   SDM014      0.5           B 366.3350 225.0610 203.588
 226   SDM016      0.5           B 305.6080 381.5770 155.052
 245   SDM017      0.5           B 223.6260 281.7830 182.374
 264   SDM018      0.5           B 200.7720 401.6350 193.573
 283   SDM019      0.5         

Re: [R] merging multiple data frames

2010-09-23 Thread Mike Rennie
First, you might want to start by generating a new column to identify your
'pdf and bdf or whatever once it's merged.

For the merging, see

?merge

But as someone's already pointed out, it's not clear what you are trying to
merge by.

Also, as your example calculations show, you don't need to merge it to to
the calcuations you want to do...

On Thu, Sep 23, 2010 at 8:53 AM, Steve Lianoglou 
mailinglist.honey...@gmail.com wrote:

 Hi,

 On Thu, Sep 23, 2010 at 9:04 AM, rasanpreet rasanpreet.k...@gmail.com
 wrote:
 
  hi guys
  i have multiple data frames which i want to  merge.
  there are four of them..eg

 Can you provide a (correct) example of what you want your merged
 data.frame to look like?
 What column do you want to use in your data.frame to merge against?
 I'm guessing SampleID(?), but then again, these aren't unique in your
 `pdf` data.frame. For instance, what would the row for SDM001 look
 like in your merged data.frame?

 -steve

  pdf
 
  SampleID UVDose_J RepairHours   Day_0  Day_45  Day_90
  1SDM001  1.0   3 485.612 465.142 490.873
  2SDM001  1.0   3 503.658 457.863 487.783
  3SDM001  1.0   2 533.193 451.044 456.973
  4SDM001  1.0   2 538.334 452.887 474.915
  5SDM001  1.0   1 526.034 481.123 477.801
  6SDM001  1.0   1 546.543 472.322 481.546
  7SDM001  1.0   0  NA  NA  NA
  8SDM001  1.0   0  NA  NA  NA
  9SDM001  0.5   3 432.134 457.245 497.975
  10   SDM001  0.5   3 432.605 450.184 489.468
  11   SDM001  0.5   2 450.335 496.520 488.784
  12   SDM001  0.5   2 439.590 474.371 470.182
  13   SDM001  0.5   1 510.480 489.561 525.029
  14   SDM001  0.5   1 487.934 467.258 488.784
  15   SDM001  0.5   0  NA  NA  NA
  16   SDM001  0.5   0  NA  NA  NA
  20   SDM002  1.0   3 465.549 528.715 501.374
  21   SDM002  1.0   3 458.168 505.480 489.244
  22   SDM002  1.0   2 447.317 464.009 478.058
  23   SDM002  1.0   2 452.020 438.446 470.996
  24   SDM002  1.0   1 441.718 458.760 499.221
  25   SDM002  1.0   1 447.017 402.616 548.797
  26   SDM002  1.0   0  NA  NA  NA
  27   SDM002  1.0   0  NA  NA  NA
  28   SDM002  0.5   3 421.409 448.870 476.392
  29   SDM002  0.5   3 404.089 446.413 477.080
  30   SDM002  0.5   2 399.775 432.678 465.015
  31   SDM002  0.5   2 427.157 443.418 477.048
  32   SDM002  0.5   1 389.674 449.353 482.264
  33   SDM002  0.5   1 418.147 455.983 495.486
  34   SDM002  0.5   0  NA  NA  NA
  35   SDM002  0.5   0  NA  NA  NA
  39   SDM005  1.0   3 579.836 441.040 476.382
  40   SDM005  1.0   3 578.525 443.875 472.867
  41   SDM005  1.0   2 564.266 432.116 469.416
  42   SDM005  1.0   2 571.045 447.658 458.233
  43   SDM005  1.0   1 564.664 427.673 524.122
  44   SDM005  1.0   1 568.182 458.039 477.237
  45   SDM005  1.0   0  NA  NA  NA
  46   SDM005  1.0   0  NA  NA  NA
  47   SDM005  0.5   3 556.534 424.786 501.658
  48   SDM005  0.5   3 474.027 441.418 507.635
  49   SDM005  0.5   2 481.355 430.346 468.021
  50   SDM005  0.5   2 478.922 466.933 471.025
  51   SDM005  0.5   1 505.539 937.759 460.985
  52   SDM005  0.5   1 497.913 457.932 493.152
  53   SDM005  0.5   0  NA  NA  NA
  54   SDM005  0.5   0  NA  NA  NA
  58   SDM006  1.0   3 589.164 459.578 509.565
  59   SDM006  1.0   3 608.477 480.233 519.785
  60   SDM006  1.0   2 598.354 449.266 487.058
  61   SDM006  1.0   2 617.823 456.908 507.467
  62   SDM006  1.0   1 566.477 500.189 526.744
  63   SDM006  1.0   1 622.170 462.463 550.675
  64   SDM006  1.0   0  NA  NA  NA
  65   SDM006  1.0   0  NA  NA  NA
  66   SDM006  0.5   3 546.472 457.880 468.129
  67   SDM006  0.5   3 525.069 444.575 505.154
  68   SDM006  0.5   2 569.068 446.196 473.739
  69   SDM006  0.5   2 534.205 470.366 476.570
 
  bdf
  SampleID UVDose_J RepairHoursDay_0   Day_45  Day_90
  17SDM001  0.5   B  88.6145 388.3575 198.467
  36SDM002  0.5   B 100.0760 384.9505 234.740
  55SDM005  0.5   B 121.9595 300.3650 241.832
  74SDM006  0.5   B 174.7005 378.3435 291.272
  93SDM007  0.5   B 319.7750 335.4390 110.306
  112   SDM008  0.5   B 292.8400 323.0370 

Re: [R] merging multiple data frames

2010-09-23 Thread rasanpreet kaur suri
hi guys..thx for help
i have to perform a calculation
P-B/T-B
where P is the values in pdf and B is the values in bdf and T in tdf


On Thu, Sep 23, 2010 at 7:49 PM, Mike Rennie mikerenni...@gmail.com wrote:

 First, you might want to start by generating a new column to identify your
 'pdf and bdf or whatever once it's merged.

 For the merging, see

 ?merge

 But as someone's already pointed out, it's not clear what you are trying to
 merge by.

 Also, as your example calculations show, you don't need to merge it to to
 the calcuations you want to do...

 On Thu, Sep 23, 2010 at 8:53 AM, Steve Lianoglou 
 mailinglist.honey...@gmail.com wrote:

 Hi,

 On Thu, Sep 23, 2010 at 9:04 AM, rasanpreet rasanpreet.k...@gmail.com
 wrote:
 
  hi guys
  i have multiple data frames which i want to  merge.
  there are four of them..eg

 Can you provide a (correct) example of what you want your merged
 data.frame to look like?
 What column do you want to use in your data.frame to merge against?
 I'm guessing SampleID(?), but then again, these aren't unique in your
 `pdf` data.frame. For instance, what would the row for SDM001 look
 like in your merged data.frame?

 -steve

  pdf
 
  SampleID UVDose_J RepairHours   Day_0  Day_45  Day_90
  1SDM001  1.0   3 485.612 465.142 490.873
  2SDM001  1.0   3 503.658 457.863 487.783
  3SDM001  1.0   2 533.193 451.044 456.973
  4SDM001  1.0   2 538.334 452.887 474.915
  5SDM001  1.0   1 526.034 481.123 477.801
  6SDM001  1.0   1 546.543 472.322 481.546
  7SDM001  1.0   0  NA  NA  NA
  8SDM001  1.0   0  NA  NA  NA
  9SDM001  0.5   3 432.134 457.245 497.975
  10   SDM001  0.5   3 432.605 450.184 489.468
  11   SDM001  0.5   2 450.335 496.520 488.784
  12   SDM001  0.5   2 439.590 474.371 470.182
  13   SDM001  0.5   1 510.480 489.561 525.029
  14   SDM001  0.5   1 487.934 467.258 488.784
  15   SDM001  0.5   0  NA  NA  NA
  16   SDM001  0.5   0  NA  NA  NA
  20   SDM002  1.0   3 465.549 528.715 501.374
  21   SDM002  1.0   3 458.168 505.480 489.244
  22   SDM002  1.0   2 447.317 464.009 478.058
  23   SDM002  1.0   2 452.020 438.446 470.996
  24   SDM002  1.0   1 441.718 458.760 499.221
  25   SDM002  1.0   1 447.017 402.616 548.797
  26   SDM002  1.0   0  NA  NA  NA
  27   SDM002  1.0   0  NA  NA  NA
  28   SDM002  0.5   3 421.409 448.870 476.392
  29   SDM002  0.5   3 404.089 446.413 477.080
  30   SDM002  0.5   2 399.775 432.678 465.015
  31   SDM002  0.5   2 427.157 443.418 477.048
  32   SDM002  0.5   1 389.674 449.353 482.264
  33   SDM002  0.5   1 418.147 455.983 495.486
  34   SDM002  0.5   0  NA  NA  NA
  35   SDM002  0.5   0  NA  NA  NA
  39   SDM005  1.0   3 579.836 441.040 476.382
  40   SDM005  1.0   3 578.525 443.875 472.867
  41   SDM005  1.0   2 564.266 432.116 469.416
  42   SDM005  1.0   2 571.045 447.658 458.233
  43   SDM005  1.0   1 564.664 427.673 524.122
  44   SDM005  1.0   1 568.182 458.039 477.237
  45   SDM005  1.0   0  NA  NA  NA
  46   SDM005  1.0   0  NA  NA  NA
  47   SDM005  0.5   3 556.534 424.786 501.658
  48   SDM005  0.5   3 474.027 441.418 507.635
  49   SDM005  0.5   2 481.355 430.346 468.021
  50   SDM005  0.5   2 478.922 466.933 471.025
  51   SDM005  0.5   1 505.539 937.759 460.985
  52   SDM005  0.5   1 497.913 457.932 493.152
  53   SDM005  0.5   0  NA  NA  NA
  54   SDM005  0.5   0  NA  NA  NA
  58   SDM006  1.0   3 589.164 459.578 509.565
  59   SDM006  1.0   3 608.477 480.233 519.785
  60   SDM006  1.0   2 598.354 449.266 487.058
  61   SDM006  1.0   2 617.823 456.908 507.467
  62   SDM006  1.0   1 566.477 500.189 526.744
  63   SDM006  1.0   1 622.170 462.463 550.675
  64   SDM006  1.0   0  NA  NA  NA
  65   SDM006  1.0   0  NA  NA  NA
  66   SDM006  0.5   3 546.472 457.880 468.129
  67   SDM006  0.5   3 525.069 444.575 505.154
  68   SDM006  0.5   2 569.068 446.196 473.739
  69   SDM006  0.5   2 534.205 470.366 476.570
 
  bdf
  SampleID UVDose_J RepairHoursDay_0   Day_45  Day_90
  17SDM001  0.5   B  88.6145 388.3575 198.467
  36SDM002  0.5   B 100.0760 384.9505 234.740
  55SDM005  0.5 

Re: [R] merging multiple data frames

2010-09-23 Thread Steve Lianoglou
On Thu, Sep 23, 2010 at 12:18 PM, rasanpreet kaur suri
rasanpreet.k...@gmail.com wrote:
 hi guys..thx for help
 i have to perform a calculation
 P-B/T-B
 where P is the values in pdf and B is the values in bdf and T in tdf

You have 69 rows in your pdf data.frame, and something like 20 rows in
bdf and tdf, so my original question stands:

 What column do you want to use in your data.frame to merge against?
 I'm guessing SampleID(?), but then again, these aren't unique in your
 `pdf` data.frame. For instance, what would the row for SDM001 look
 like in your merged data.frame?

You know what I mean? How do you intend to group the rows across your
pdf,bdf,tdf to do this calculation?

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] merging multiple data frames based on X and Y coordinates

2009-04-17 Thread ddepew

Hi all,
I'm a little stumped on this.
I have 5 data frames with continuous GPS coordinates at 5 to 10 m  
spacing. Due to the different GPS units used, data collected within  
one to two sec apart have coordinates that differ by 3 to 5 m on  
average. I'd like to aggrate the data frames relative to the one with  
the most continuous data stream, but I have no ideas how to specify a  
distance tolerance, (say 5 m ?) when using merge

Does anyone know of a suitable function that might accomplish this?

Thanks in advance...

__
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] merging multiple data frames with different numbers of rows

2008-04-29 Thread stephen sefick
merge can only merge two objects at a time- I would like to merge more than
two objects at a time.

s.d - structure(list(RiverMile = c(202L, 198L, 190L, 185L, 179L, 148L,
119L, 61L)), .Names = RiverMile, row.names = c(NA, -8L), class =
data.frame)
#s.d is all of the river miles that can occur in all of the data frames that

I want to put together

feb06 - structure(list(RiverMile = c(202L, 190L, 185L), X2.1.06 =
c(285,
NA, NA)), .Names = c(RiverMile, X2.1.06), row.names = c(29L,
31L, 32L), class = data.frame)

may06 - structure(list(RiverMile = c(202L, 198L, 190L, 185L, 148L), X5.1.06

= c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_)), .Names = c(RiverMile,
X5.1.06), row.names = c(29L, 30L, 31L, 32L, 34L), class = data.frame)

jun06 - structure(list(RiverMile = c(202L, 198L, 190L, 185L, 148L), X6.1.06
= c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_)), .Names = c(RiverMile,
X6.1.06), row.names = c(29L, 30L, 31L, 32L, 34L), class = data.frame)

merge(s.d, feb06, all=T)
  RiverMile X2.1.06
161  NA
2   119  NA
3   148  NA
4   179  NA
5   185  NA
6   190  NA
7   198  NA
8   202 285

#this is what I want- is there a way to implement this over many data frames

-- 
Let's not spend our time and resources thinking about things that are so
little or so large that all they really do for us is puff us up and make us
feel like gods. We are mammals, and have not exhausted the annoying little
problems of being mammals.

-K. Mullis

[[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] merging multiple data frames with different numbers of rows

2008-04-29 Thread Gabor Grothendieck
It appears that these are time series (i.e. there is only one value of
River Mile in any one data frame) so if that's right you would be better
off representing them as time series.  Using zoo:

 library(zoo)
 feb06.z - zoo(feb06[,2], feb06[,1])
 may06.z - zoo(may06[,2], may06[,1])
 jun06.z - zoo(jun06[,2], jun06[,1])
 merge(feb06.z, may06.z, jun06.z)
feb06.z may06.z jun06.z
148  NA  NA  NA
185  NA  NA  NA
190  NA  NA  NA
198  NA  NA  NA
202 285  NA  NA

Alternately this also works:

 L - list(feb06 = feb06, may06 = may06, jun06 = jun06)
 do.call(merge, lapply(L, function(x) zoo(x[,2], x[,1])))
  feb06 may06 jun06
148  NANANA
185  NANANA
190  NANANA
198  NANANA
202 285NANA



Read the three vignettes that come with zoo and also ?merge.zoo

On Tue, Apr 29, 2008 at 10:42 AM, stephen sefick [EMAIL PROTECTED] wrote:
 merge can only merge two objects at a time- I would like to merge more than
 two objects at a time.

 s.d - structure(list(RiverMile = c(202L, 198L, 190L, 185L, 179L, 148L,
 119L, 61L)), .Names = RiverMile, row.names = c(NA, -8L), class =
 data.frame)
 #s.d is all of the river miles that can occur in all of the data frames that

 I want to put together

 feb06 - structure(list(RiverMile = c(202L, 190L, 185L), X2.1.06 =
 c(285,
 NA, NA)), .Names = c(RiverMile, X2.1.06), row.names = c(29L,
 31L, 32L), class = data.frame)

 may06 - structure(list(RiverMile = c(202L, 198L, 190L, 185L, 148L), X5.1.06

 = c(NA_real_,
 NA_real_, NA_real_, NA_real_, NA_real_)), .Names = c(RiverMile,
 X5.1.06), row.names = c(29L, 30L, 31L, 32L, 34L), class = data.frame)

 jun06 - structure(list(RiverMile = c(202L, 198L, 190L, 185L, 148L), X6.1.06
 = c(NA_real_,
 NA_real_, NA_real_, NA_real_, NA_real_)), .Names = c(RiverMile,
 X6.1.06), row.names = c(29L, 30L, 31L, 32L, 34L), class = data.frame)

 merge(s.d, feb06, all=T)
  RiverMile X2.1.06
 161  NA
 2   119  NA
 3   148  NA
 4   179  NA
 5   185  NA
 6   190  NA
 7   198  NA
 8   202 285

 #this is what I want- is there a way to implement this over many data frames

 --
 Let's not spend our time and resources thinking about things that are so
 little or so large that all they really do for us is puff us up and make us
 feel like gods. We are mammals, and have not exhausted the annoying little
 problems of being mammals.

 -K. Mullis

[[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.