s-news
[Top] [All Lists]

Adding to a data frame

To: S-News <s-news@wubios.wustl.edu>
Subject: Adding to a data frame
From: Kim Elmore <Kim.Elmore@noaa.gov>
Date: Tue, 13 Nov 2007 11:30:51 -0600
User-agent: Thunderbird 2.0.0.6 (Windows/20070728)
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

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