我有一个像这样打印的未知 R 对象。如何迭代值并打印它们?
print(myRobject)
[[1]]
theTicker thePeriodEnded
"MSFT" "31-03-2013"
theRevenueRaw theNetIncomeRaw
"20489" "6055"
theEarningsPerShareBasicRaw theWeightedAveSharesBasicRaw
"0.72" "8364"
theCashDivDeclPerCommonShareRaw theNetCashFromOperationsRaw "0.23" "9666"
[[2]]
theTicker thePeriodEnded
"XXXX" "31-03-2013"
theRevenueRaw theNetIncomeRaw
"20489" "6055"
theEarningsPerShareBasicRaw theWeightedAveSharesBasicRaw
"0.72" "8364"
theCashDivDeclPerCommonShareRaw theNetCashFromOperationsRaw "0.23" "9666"
Dean 和 Metrics,这里有一些结果。如何将“theTicker”与“MSFT”分开,以便(最终)循环?
字符串(我的对象)
List of 1
$ : Named chr [1:8] "MSFT" "31-03-2013" "20489" "6055" ...
..- attr(*, "names")= chr [1:8] "theTicker" "thePeriodEnded" "theRevenueRaw" "theNetIncomeRaw" ...
我的对象[[1]]
WORKS - returns just list item 1
myRobject[[1]]["theTicker"]
theTicker
"MSFT"
str(myRobject[[1]]["theTicker"])
Named chr "MSFT"
- attr(*, "names")= chr "theTicker"
require(plyr) 加载所需的包:plyr ldply(myRobject, identity)
theTicker thePeriodEnded theRevenueRaw theNetIncomeRaw
1 MSFT 31-03-2013 20489 6055
2 XXXX 31-03-2013 20489 6055
theEarningsPerShareBasicRaw theWeightedAveSharesBasicRaw
1 0.72 8364
2 0.72 8364
theCashDivDeclPerCommonShareRaw theNetCashFromOperationsRaw
1 0.23 9666
2 0.23 9666
出[[1]][“TheTicker”][1]
theTicker
"MSFT"
出[[1]][“TheTicker”][2]
<NA>
NA
出[[1]]["theTicker"]["1"]
<NA>
NA
出[[1]]["theTicker"][["1"]]
ERROR
出[[1]]["TheTicker"]$1
ERROR
出[[1]]["theTicker"][1,1]
Error in out[[1]]["theTicker"][1, 1] : incorrect number of dimensions
出[[1]][“TheTicker”][1]
theTicker
"MSFT"
出[[1]][“TheTicker”][1][1]
theTicker
"MSFT"
出[[1]][“TheTicker”][1][2]
<NA>
NA
出[[1]][“TheTicker”][1][1][1]
theTicker
"MSFT"
do.call(rbind,myRobject)
theTicker thePeriodEnded theRevenueRaw theNetIncomeRaw
[1,] "MSFT" "31-03-2013" "20489" "6055"
[2,] "XXXX" "31-03-2013" "20489" "6055"
theEarningsPerShareBasicRaw theWeightedAveSharesBasicRaw
[1,] "0.72" "8364"
[2,] "0.72" "8364"
theCashDivDeclPerCommonShareRaw theNetCashFromOperationsRaw
[1,] "0.23" "9666"
[2,] "0.23" "9666"
股票代码<-list(myRobject[[1]][1],myRobject[[2]][1])
股票代码
[[1]]
theTicker
"MSFT"
[[2]]
theTicker
"XXXX"
周期<-list(myRobject[[1]][2],myRobject[[2]][2])
period
[[1]]
thePeriodEnded
"31-03-2013"
[[2]]
thePeriodEnded
"31-03-2013"
再次,我如何将“theTicker”与“MSFT”分开,所以我可以(最终)循环?