Zoo オブジェクトにデータ セットがあります。行をループし、それらから変数を抽出し、各行のデータ フレームを出力する関数を使用してそれらを実行しています。次に、これらの出力データを、元の動物園オブジェクトと一致する行を持つデータ フレームに結合します。それらを組み合わせて、新しい列を元の動物園に追加したいと思います。
私のデータはtestZです
> testZ
X107b_pH X107b_SP X107b_temp Sal TApred
(06/22/12 03:00:00) 8.5124 7.32 16.16140 29.5935 2061.212
(06/22/12 04:00:00) 8.5124 7.32 15.93407 30.0677 2083.886
(06/22/12 05:00:00) 8.5124 7.32 15.76140 30.1329 2087.003
(06/22/12 06:00:00) 8.5124 7.32 15.59807 29.9522 2078.363
(06/22/12 07:00:00) 8.5124 7.32 15.46307 29.9091 2076.303
(06/22/12 08:00:00) 8.5124 7.32 15.44640 29.8565 2073.788
(06/22/12 09:00:00) 8.5124 7.32 15.44640 29.8647 2074.180
(06/22/12 10:00:00) 8.5124 7.32 15.44640 29.8568 2073.802
(06/22/12 11:00:00) 8.5124 7.32 15.47640 29.8092 2071.526
(06/22/12 12:00:00) 8.5124 7.32 15.58640 29.7966 2070.923
(06/22/12 13:00:00) 8.5124 7.32 15.60712 29.8247 2072.267
および testS (seacarb パッケージの carb 関数からの出力)
> testS
flag S T P pH CO2 pCO2 fCO2 HCO3 CO3 DIC ALK OmegaAragonite OmegaCalcite
100 8 29.5935 16.16140 0 8.5124 3.640861e-06 98.00598 97.66177 0.001327675 0.0002942433 0.001625559 0.002061212 4.618012 7.265870
101 8 30.0677 15.93407 0 8.5124 3.676374e-06 98.55170 98.20457 0.001340472 0.0002981053 0.001642254 0.002083886 4.668223 7.337512
102 8 30.1329 15.76140 0 8.5124 3.700343e-06 98.71823 98.36976 0.001344778 0.0002975873 0.001646066 0.002087003 4.656435 7.320294
103 8 29.9522 15.59807 0 8.5124 3.720354e-06 98.66681 98.31780 0.001344355 0.0002942804 0.001642355 0.002078363 4.604700 7.245624
104 8 29.9091 15.46307 0 8.5124 3.738210e-06 98.71419 98.36442 0.001345958 0.0002927887 0.001642485 0.002076303 4.579875 7.209657
105 8 29.8565 15.44640 0 8.5124 3.739859e-06 98.67915 98.32943 0.001345269 0.0002920590 0.001641068 0.002073788 4.568917 7.193862
106 8 29.8647 15.44640 0 8.5124 3.739957e-06 98.68623 98.33648 0.001345423 0.0002921536 0.001641317 0.002074180 4.570287 7.195833
107 8 29.8568 15.44640 0 8.5124 3.739863e-06 98.67941 98.32969 0.001345275 0.0002920624 0.001641077 0.002073802 4.568967 7.193934
108 8 29.8092 15.47640 0 8.5124 3.735212e-06 98.61975 98.27037 0.001343849 0.0002917330 0.001639318 0.002071526 4.564912 7.188167
109 8 29.7966 15.58640 0 8.5124 3.720121e-06 98.54050 98.19189 0.001341659 0.0002923933 0.001637773 0.002070923 4.577113 7.205942
110 8 29.8247 15.60712 0 8.5124 3.717640e-06 98.55167 98.20311 0.001341816 0.0002928703 0.001638404 0.002072267 4.584520 7.216633
cbind を試してみましたが、不可解な結果が得られました。私が使用する場合
testM=cbind(testZ,testS$pCO2)
それは私が期待することを行い、pCO2 列を動物園オブジェクト testZ に追加します。ただし、次のように呼び出しても機能しません。
> testM=cbind(testZ,testS)
Warning message:
In cbind(testZ, testS) :
number of rows of result is not a multiple of vector length (arg 2)
提案をありがとう。私は動物園が初めてなので、何かを見落としている可能性があります。
dput() 出力:
> dput(testZ)
structure(c(8.5124, 8.5124, 8.5124, 8.5124, 8.5124, 8.5124, 8.5124,
8.5124, 8.5124, 8.5124, 8.5124, 7.32, 7.32, 7.32, 7.32, 7.32,
7.32, 7.32, 7.32, 7.32, 7.32, 7.32, 16.1614, 15.9340666666667,
15.7614, 15.5980666666667, 15.4630666666667, 15.4464, 15.4464,
15.4464, 15.4764, 15.5864, 15.6071216666667, 29.5935, 30.0677,
30.1329, 29.9522, 29.9091, 29.8565, 29.8647, 29.8568, 29.8092,
29.7966, 29.8247, 2061.2124, 2083.885921, 2087.00341, 2078.363374,
2076.30258, 2073.78755, 2074.179627, 2073.801894, 2071.525935,
2070.923476, 2072.267056), .Dim = c(11L, 5L), .Dimnames = list(
NULL, c("X107b_pH", "X107b_SP", "X107b_temp", "Sal", "TApred"
)), index = structure(c(15513.125, 15513.1666666667, 15513.2083333333,
15513.25, 15513.2916666667, 15513.3333333333, 15513.375, 15513.4166666667,
15513.4583333333, 15513.5, 15513.5416666667), format = structure(c("m/d/y",
"h:m:s"), .Names = c("dates", "times")), origin = c(1, 1, 1970
), class = c("chron", "dates", "times")), class = "zoo")
> dput(testS)
structure(list(flag = c(8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), S = c(29.5935,
30.0677, 30.1329, 29.9522, 29.9091, 29.8565, 29.8647, 29.8568,
29.8092, 29.7966, 29.8247), T = c(16.1614, 15.9340666666667,
15.7614, 15.5980666666667, 15.4630666666667, 15.4464, 15.4464,
15.4464, 15.4764, 15.5864, 15.6071216666667), P = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0), pH = c(8.5124, 8.5124, 8.5124, 8.5124,
8.5124, 8.5124, 8.5124, 8.5124, 8.5124, 8.5124, 8.5124), CO2 = c(3.64086135363789e-06,
3.67637421195346e-06, 3.70034276494183e-06, 3.72035392339414e-06,
3.73820956050126e-06, 3.73985945475865e-06, 3.73995661519692e-06,
3.73986300857744e-06, 3.73521210447936e-06, 3.7201209120172e-06,
3.71764026477019e-06), pCO2 = c(98.005982410781, 98.551699365364,
98.7182334593185, 98.6668114430222, 98.7141900061466, 98.6791533613055,
98.6862308435365, 98.6794122638734, 98.6197523510141, 98.5405045633332,
98.5516674237132), fCO2 = c(97.6617674560379, 98.2045735556704,
98.3697621203092, 98.3178020344274, 98.3644164625271, 98.3294302472383,
98.3364826465715, 98.3296882322446, 98.270372350004, 98.1918905249818,
98.2031052068924), HCO3 = c(0.00132767523331992, 0.00134047197543355,
0.00134477847686806, 0.00134435458599512, 0.00134595801586938,
0.00134526939095695, 0.00134542309836435, 0.00134527501465186,
0.00134384946047717, 0.00134165916833029, 0.00134181561030948
), CO3 = c(0.0002942433395289, 0.000298105334561092, 0.000297587342867106,
0.000294280388575961, 0.000292788714950415, 0.000292058968639722,
0.000292153613334272, 0.000292062431011073, 0.000291732984210706,
0.000292393341741146, 0.000292870295328662), DIC = c(0.00162555943420246,
0.0016422536842066, 0.00164606616250011, 0.00164235532849448,
0.0016424849403803, 0.00164106821905143, 0.00164131666831381,
0.00164107730867151, 0.00163931765679236, 0.00163777263098345,
0.00163840354590291), ALK = c(0.0020612124, 0.002083885921, 0.00208700341,
0.002078363374, 0.00207630258, 0.00207378755, 0.002074179627,
0.002073801894, 0.002071525935, 0.002070923476, 0.002072267056
), OmegaAragonite = c(4.61801172079652, 4.66822300723876, 4.6564345684589,
4.60469962461282, 4.57987479287612, 4.56891702268792, 4.5702869874125,
4.56896714300747, 4.56491213342598, 4.57711290054851, 4.58452034914768
), OmegaCalcite = c(7.2658700466138, 7.33751216404482, 7.32029446048522,
7.2456237796818, 7.20965711830326, 7.1938623694745, 7.19583268801109,
7.19393445299217, 7.18816712299541, 7.20594221223447, 7.21663254411275
)), .Names = c("flag", "S", "T", "P", "pH", "CO2", "pCO2", "fCO2",
"HCO3", "CO3", "DIC", "ALK", "OmegaAragonite", "OmegaCalcite"
), row.names = 100:110, class = "data.frame")