私は以下のようなリストオブジェクトを持っています:
structure(list(bga_u = structure(list(buy_target_price = numeric(0),
sell_target_price = numeric(0), units_holding = 0, tx_record = structure(list(
`2010-12-01` = structure(list(buy_date = structure(14944, class = "Date"),
offer_price = 40.58, buy_unit = 3.15931809278285,
status = "hold"), .Names = c("buy_date", "offer_price",
"buy_unit", "status")), `2011-01-03` = structure(list(
buy_date = structure(14977, class = "Date"), offer_price = 42.2,
buy_unit = 3.03803621339166, status = "hold"), .Names = c("buy_date",
"offer_price", "buy_unit", "status")), `2011-02-01` = structure(list(
buy_date = structure(15006, class = "Date"), offer_price = 42.59,
buy_unit = 3.01021667539629, status = "hold"), .Names = c("buy_date",
"offer_price", "buy_unit", "status")), `2011-03-01` = structure(list(
buy_date = structure(15034, class = "Date"), offer_price = 43.37,
buy_unit = 2.95607858439309, status = "hold"), .Names = c("buy_date",
"offer_price", "buy_unit", "status")), `2011-04-01` = structure(list(
buy_date = structure(15065, class = "Date"), offer_price = 43.35,
buy_unit = 2.95744240380919, status = "hold"), .Names = c("buy_date",
"offer_price", "buy_unit", "status")), `2011-05-03` = structure(list(
buy_date = structure(15097, class = "Date"), offer_price = 44.53,
buy_unit = 2.87907316876551, status = "hold"), .Names = c("buy_date",
"offer_price", "buy_unit", "status"))), .Names = c("2010-12-01",
"2011-01-03", "2011-02-01", "2011-03-01", "2011-04-01", "2011-05-03"
))), .Names = c("buy_target_price", "sell_target_price",
"units_holding", "tx_record")), bwg_u = structure(list(buy_target_price = numeric(0),
sell_target_price = numeric(0), units_holding = 0, tx_record = structure(list(
`2010-11-02` = structure(list(buy_date = structure(14915, class = "Date"),
offer_price = 63.15, buy_unit = 2.03016830095215,
status = "hold"), .Names = c("buy_date", "offer_price",
"buy_unit", "status")), `2010-12-01` = structure(list(
buy_date = structure(14944, class = "Date"), offer_price = 64.19,
buy_unit = 1.99727571592348, status = "hold"), .Names = c("buy_date",
"offer_price", "buy_unit", "status")), `2011-09-01` = structure(list(
buy_date = structure(15218, class = "Date"), offer_price = 69.29,
buy_unit = 1.85026884406304, status = "hold"), .Names = c("buy_date",
"offer_price", "buy_unit", "status")), `2011-10-03` = structure(list(
buy_date = structure(15250, class = "Date"), offer_price = 58.05,
buy_unit = 2.20852934031229, status = "hold"), .Names = c("buy_date",
"offer_price", "buy_unit", "status"))), .Names = c("2010-11-02",
"2010-12-01", "2011-09-01", "2011-10-03"))), .Names = c("buy_target_price",
"sell_target_price", "units_holding", "tx_record"))), .Names = c("bga_u",
"bwg_u"))
これは、3 つのレベルで構成される「リスト内のリスト」オブジェクトです。
- レベル 1: すべてのファンドの名前 (ここでは 2 つのファンド:
bga
_u とbwg_u
) - レベル 2: 目標購入価格; 目標販売価格; とユニット保有
- レベル 3: 特定の取引の詳細 (購入したユニットなど)
レベル 2 に保存されている「保有単位」は、特定の取引のステータスがまだ「保持」である場合、各取引のレベル 3 の「購入単位」を合計することによって計算されます。
各ファンドの「保有単位」を計算してレベル 2 にするにはどうすればよいですか?
(私は R を 2 ~ 3 年間使用しましたが、このlist
オブジェクトに慣れていないため、概念的に間違っている可能性がありますlist
。)