[R] Conditionally constructing columns in a data frame

Stuart Luppescu slu at ccsr.uchicago.edu
Tue Jun 29 21:22:45 CEST 2010


On Tue, 2010-06-29 at 13:59 -0500, Erik Iverson wrote:
> I'm sure there's an easier way, but it's going to be easiest to get a 
> useful response if we have a reproducible, minimal example, as the 
> posting guide requests. ?tapply is probably involved.

A minimal example of data? How about this:

    era1base  eb1base era1tr eb1tr era2tr eb2tr   era3tr    eb3tr existstr
11  207.9367 -5.08916     NA    NA     NA    NA  0.40376  0.70781      001
25  205.5631 -7.46273     NA    NA     NA    NA  0.24351  0.54757      001
38  211.3405 -1.68539     NA    NA     NA    NA  0.16300  0.46706      001
40  207.7364 -5.28944     NA    NA     NA    NA  0.15421  0.45827      001
125 210.8997 -2.12617     NA    NA     NA    NA -0.06747  0.23659      001
128 210.4231 -2.60274     NA    NA     NA    NA -0.07540  0.22865      001
129 209.0014 -4.02449     NA    NA     NA    NA -0.07750  0.22656      001
140 205.7868 -7.23908     NA    NA     NA    NA -0.09669  0.20737      001
147 204.7511 -8.27474     NA    NA     NA    NA -0.12341  0.18065      001
199 214.5837  1.55783     NA    NA     NA    NA -0.19735  0.10671      001
217 210.2797 -2.74620     NA    NA     NA    NA -0.22830  0.07576      001
220 210.8241 -2.20176     NA    NA     NA    NA -0.23292  0.07114      001
230 214.1677  1.14188     NA    NA     NA    NA -0.24546  0.05860      001
23  204.5346  -8.49127     NA    NA 0.97800  0.05710  0.25214  0.55620      011
45  200.6664 -12.35943     NA    NA 0.85315 -0.06774  0.13930  0.44336      011
61  206.5377  -6.48822     NA    NA 1.35338  0.43248  0.08575  0.38980      011
78  204.1361  -8.88975     NA    NA 1.23077  0.30988  0.02840  0.33246      011
87  205.8586  -7.16726     NA    NA 1.27300  0.35210  0.01372  0.31778      011
98  214.8767   1.85082     NA    NA 0.05363 -0.86727 -0.01741  0.28665      011
100 204.2501  -8.77575     NA    NA 1.75940  0.83850 -0.01860  0.28545      011
133 215.9762   2.95033     NA    NA 0.54176 -0.37914 -0.08791  0.21615      011
211 209.5723  -3.45358     NA    NA 0.85139 -0.06951 -0.21637  0.08769      011
523 206.0448 -6.98104 1.02349 0.65789     NA    NA     NA    NA      100
524 215.9634  2.93754 0.37856 0.01297     NA    NA     NA    NA      100

-- 
Stuart Luppescu <slu at ccsr.uchicago.edu>
University of Chicago


More information about the R-help mailing list