s-news
[Top] [All Lists]

RE Adding to a data frame

To: s-news@lists.biostat.wustl.edu
Subject: RE Adding to a data frame
From: gerald.jean@dgag.ca
Date: Tue, 13 Nov 2007 12:51:42 -0500
In-reply-to: <4739DF4B.3060203@noaa.gov>
Hello Kim,

look at the doc. for the function "merge", you can specify by which column
to merge and there is many other options.

Gérald Jean
Conseiller senior en statistiques, Actuariat
télephone            : (418) 835-4900 poste (7639)
télecopieur          : (418) 835-6657
courrier électronique: gerald.jean@dgag.ca

"In God we trust, all others must bring data"  W. Edwards Deming



                                                                           
             Kim Elmore                                                    
             <Kim.Elmore@noaa.                                             
             gov>                                                        A 
             Envoyé par :              S-News <s-news@wubios.wustl.edu>    
             s-news-owner@list                                          cc 
             s.biostat.wustl.e                                             
             du                                                      Objet 
                                       [S] Adding to a data frame          
                                                                           
             2007/11/13 12:31                                              
                                                                           
                                                                           
             Veuillez répondre                                             
                     à                                                     
             s-news@lists.bios                                             
               tat.wustl.edu                                               
                                                                           
                                                                           




I have a data frame with entries something like the following:

index  value1  value2  value3
1          0.5          3.5      4
1          1.0          4.0      5
1          1.5          5.0      6
1          3.0          3.5      7
2          0.6          3.2      4
2          1.5          3.8      7
2          2.8          3.3      7
3          0.8          4.2      9
etc

I have another data frame that looks like this:

index  value4  value5  value6
1         33.4     106.9   78
2         34.5     107.0   88
3         32.8     108.2   90
etc

Keying on the "index" value, I want to merge these two data frames to
get the following:

index  value1  value2  value3  value4  value5  value6
1          0.5          3.5      4       33.4     106.9   78
1          1.0          4.0      5       33.4     106.9   78
1          1.5          5.0      6       33.4     106.9   78
1          3.0          3.5      7       33.4     106.9   78
2          0.6          3.2      4       34.5     107.0   88
2          1.5          3.8      7       34.5     107.0   88
2          2.8          3.3      7       34.5     107.0   88
3          0.8          4.2      9       32.8     108.2   90
etc.

I can do this row-by-row using a for loop but that seems terribly
inefficient, especially given that I have about 30-40,000 entries to
process. How can I do this more efficiently? I've tried obvious
approaches, but all of what I dreamed up require that the two data
frames have the same number of rows.

Kim Elmore
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news



Le message ci-dessus, ainsi que les documents l'accompagnant, sont destinés
uniquement aux personnes identifiées et peuvent contenir des informations
privilégiées, confidentielles ou ne pouvant être divulguées. Si vous avez
reçu ce message par erreur, veuillez le détruire.

This communication (and/or the attachments) is intended for named
recipients only and may contain privileged or confidential information
which is not to be disclosed. If you received this communication by mistake
please destroy all copies.



<Prev in Thread] Current Thread [Next in Thread>