[R] merging 2 lists by common variable

S.McClatchie s.mcclatchie at niwa.cri.nz
Thu Feb 22 00:46:12 CET 2001


Colleagues

----------------------------------
System info:
R version rw1020 on NT
ESS using emacs ver. 20.4

----------------------------------
I want to merge 2 lists by their common factor (which is a binned time 
interval). The lists were created using

 b.opc.tr1  <- by(opc.tr1, fopc, colmean)
 b.shuttle.tr1  <- by(shuttle.tr1, fsh, colmean)

where colmean is another function to estimate the column means. 

Both lists have this structure:

>  b.shuttle.tr1

fsh: (305.96,306.02]
juliandate        lat  temp.degC 
 305.99142  -43.28905   11.85373 
------------------------------------------------------------ 
fsh: (306.02,306.09]
juliandate        lat  temp.degC 
 306.05841  -43.50886   11.68171 
------------------------------------------------------------ 
fsh: (306.09,306.16]
juliandate        lat  temp.degC 
 306.12566  -43.73148   10.99198 
------------------------------------------------------------ 
fsh: (306.16,306.23]
juliandate        lat  temp.degC 
306.192905 -43.971203   8.228907 
------------------------------------------------------------ 
fsh: (306.23,306.29]
juliandate        lat  temp.degC 
306.260174 -44.209771   7.789692 
------------------------------------------------------------ 
fsh: (306.29,306.36]
juliandate        lat  temp.degC 
 306.32742  -44.44151    7.85163 
------------------------------------------------------------ 
fsh: (306.36,306.43]
juliandate        lat  temp.degC 
306.394664 -44.671002   7.785862 
------------------------------------------------------------ 
fsh: (306.43,306.5]
juliandate        lat  temp.degC 
306.460658 -44.891848   8.459184 
> 

> b.opc.tr1

fopc: (305.96,306.02]
       time diameter.um       count 
   305.9932    410.4535      1.0000 
------------------------------------------------------------ 
fopc: (306.02,306.09]
       time diameter.um       count 
   306.0586    398.0463      1.0000 
------------------------------------------------------------ 
fopc: (306.09,306.16]
       time diameter.um       count 
   306.1329    396.4840      1.0000 
------------------------------------------------------------ 
fopc: (306.16,306.23]
       time diameter.um       count 
   306.2036    351.0583      1.0000 
------------------------------------------------------------ 
fopc: (306.23,306.29]
       time diameter.um       count 
   306.2681    395.6310      1.0000 
------------------------------------------------------------ 
fopc: (306.29,306.36]
       time diameter.um       count 
   306.3271    361.0793      1.0000 
------------------------------------------------------------ 
fopc: (306.36,306.43]
       time diameter.um       count 
   306.3907    363.0411      1.0000 
------------------------------------------------------------ 
fopc: (306.43,306.5]
       time diameter.um       count 
   306.4664    380.3839      1.0000 
> 

Normally, I would use merge() but this works on data.frames and the 
output of by() apparently cannot be coerced to a dataframe (with 
as.dataframe() for example).

I can merge the list elements one by one by looping over them, but this 
seems inefficient. Do you know of a function to merge two lists like this 
without using looping?

Thanks

Sam

Sam McClatchie, Research scientist (fisheries acoustics))))))))))
NIWA (National Institute of Water & Atmospheric Research Ltd)
PO Box 14 901, Kilbirnie, Wellington, New Zealand
s.mcclatchie at niwa.cri.nz 

                    /\
...>><xX(°> // \\
                 /// \\\   
                //// \\\\
               ///  <°)Xx><<
              /////  \\\\\\
        ><(((°>   
  >><(((°>   ...>><xX(°>O<°)Xx><<

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list