保存为单独的excel选项卡的带标签的数据框的列表

时间:2018-09-25 14:20:01

标签: r

我有多个具有以下结构的列表:

TWTR.f公司

[tox]
envlist = py36

[testenv]
deps =
    pytest
    coverage
    time
    sys
    mypackage
commands =
    python setup.py develop
    coverage erase
    coverage run -m pytest myapp/tests/
    coverage report --omit='.tox/*' 

我正在尝试将每个列表保存到单独的excel文档中,因此对于上述公司List of 3 $ IS:'data.frame': 23 obs. of 4 variables: ..$ 12/31/2017: num [1:23] 2443299 860842 1582457 539910 997107 ... ..$ 12/31/2016: num [1:23] 2529619 883240 1646379 697582 1214705 ... ..$ 12/31/2015: num [1:23] 2218032 729256 1488776 806648 1132164 ... ..$ 12/31/2014: num [1:23] 1403002 446309 956693 691543 804016 ... $ BS:'data.frame': 34 obs. of 4 variables: ..$ 12/31/2017: num [1:34] 1638413 2764689 664268 NA 10537 ... ..$ 12/31/2016: num [1:34] 988598 2785981 650650 NA 11355 ... ..$ 12/31/2015: num [1:34] 911471 2583877 638694 NA 9804 ... ..$ 12/31/2014: num [1:34] 1510724 2111154 418454 NA 28482 ... $ CF:'data.frame': 19 obs. of 4 variables: ..$ 12/31/2017: num [1:19] -108063 299367 495583 2668 8371 ... ..$ 12/31/2016: num [1:19] -456873 327572 660500 -22969 -7112 ... ..$ 12/31/2015: num [1:19] -521031 275023 658002 -216585 76355 ... ..$ 12/31/2014: num [1:19] -577820 192965 634603 -177583 18059 ... ,我试图创建一个名为TWTR.f的excel文档,其中包含3个标签为TWTR.f的工作表/工作表,ISBS

我有很多这样的列表:

TWTR.f

CF

MSFT.f

TWTR.f <- structure(list(IS = structure(list(`12/31/2017` = c(2443299, 
    860842, 1582457, 539910, 997107, NA, NA, 2397859, 45440, -140858, 
    45440, -105237, -95418, 12645, NA, -108063, NA, NA, NA, NA, -108063, 
    NA, -108063), `12/31/2016` = c(2529619, 883240, 1646379, 697582, 
    1214705, NA, NA, 2795527, -265908, -174926, -265908, -99968, 
    -440834, 16039, NA, -456873, NA, NA, NA, NA, -456873, NA, -456873
    ), `12/31/2015` = c(2218032, 729256, 1488776, 806648, 1132164, 
    NA, NA, 2668068, -450036, -83269, -450036, -98178, -533305, -12274, 
    NA, -521031, NA, NA, NA, NA, -521031, NA, -521031), `12/31/2014` = c(1403002, 
    446309, 956693, 691543, 804016, NA, NA, 1941868, -538866, -39485, 
    -538866, -35918, -578351, -531, NA, -577820, NA, NA, NA, NA, 
    -577820, NA, -577820)), .Names = c("12/31/2017", "12/31/2016", 
    "12/31/2015", "12/31/2014"), row.names = c("Total Revenue", "Cost of Revenue", 
    "Gross Profit", "Research Development", "Selling General and Administrative", 
    "Non Recurring", "Others", "Total Operating Expenses", "Operating Income or Loss", 
    "Total Other Income/Expenses Net", "Earnings Before Interest and Taxes", 
    "Interest Expense", "Income Before Tax", "Income Tax Expense", 
    "Minority Interest", "Net Income From Continuing Ops", "Discontinued Operations", 
    "Extraordinary Items", "Effect Of Accounting Changes", "Other Items", 
    "Net Income", "Preferred Stock And Other Adjustments", "Net Income Applicable To Common Shares"
    ), class = "data.frame"), BS = structure(list(`12/31/2017` = c(1638413, 
    2764689, 664268, NA, 10537, 5321884, 27600, 773715, 1188935, 
    49654, NA, 50689, NA, 7412477, 170969, 1793744, 92682, 583278, 
    1627460, 73213, NA, NA, NA, 2365259, NA, NA, NA, 4, -2671729, 
    -31579, 7750522, -31579, 5047218, 3808629), `12/31/2016` = c(988598, 
    2785981, 650650, NA, 11355, 4652196, 90200, 783901, 1185315, 
    95334, NA, 63419, NA, 6870365, 122236, 1686652, 123854, 584021, 
    1538967, 75605, NA, NA, NA, 2265430, NA, NA, NA, 4, -2550350, 
    -69253, 7224534, -69253, 4604935, 3324286), `12/31/2015` = c(911471, 
    2583877, 638694, NA, 9804, 4381792, 14200, 735299, 1122728, 141015, 
    NA, 47405, NA, 6442439, 134081, 1602956, 49950, 506039, 1455095, 
    53563, NA, NA, NA, 2074392, NA, NA, NA, 3, -2093477, -45566, 
    6507087, -45566, 4368047, 3104304), `12/31/2014` = c(1510724, 
    2111154, 418454, NA, 28482, 4255853, NA, 557019, 622570, 105011, 
    NA, 42629, NA, 5583082, 53241, 1607290, 37059, 393794, 1376020, 
    67915, NA, NA, NA, 1956679, NA, NA, NA, 3, -1572446, -10024, 
    5208870, -10024, 3626403, 2898822)), .Names = c("12/31/2017", 
    "12/31/2016", "12/31/2015", "12/31/2014"), row.names = c("Cash And Cash Equivalents", 
    "Short Term Investments", "Net Receivables", "Inventory", "Other Current Assets", 
    "Total Current Assets", "Long Term Investments", "Property Plant and Equipment", 
    "Goodwill", "Intangible Assets", "Accumulated Amortization", 
    "Other Assets", "Deferred Long Term Asset Charges", "Total Assets", 
    "Accounts Payable", "Short/Current Long Term Debt", "Other Current Liabilities", 
    "Total Current Liabilities", "Long Term Debt", "Other Liabilities", 
    "Deferred Long Term Liability Charges", "Minority Interest", 
    "Negative Goodwill", "Total Liabilities", "Misc. Stocks Options Warrants", 
    "Redeemable Preferred Stock", "Preferred Stock", "Common Stock", 
    "Retained Earnings", "Treasury Stock", "Capital Surplus", "Other Stockholder Equity", 
    "Total Stockholder Equity", "Net Tangible Assets"), class = "data.frame"), 
        CF = structure(list(`12/31/2017` = c(-108063, 299367, 495583, 
        2668, 8371, NA, -43278, 831209, -160742, 16534, -6507, -112932, 
        NA, NA, -102775, -8962, -78373, 9911, 649815), `12/31/2016` = c(-456873, 
        327572, 660500, -22969, -7112, NA, 112677, 763055, -218657, 
        -288328, -5941, -598008, NA, NA, -100558, -15388, -83975, 
        -3945, 77127), `12/31/2015` = c(-521031, 275023, 658002, 
        -216585, 76355, NA, 4317, 383066, -347280, -488830, -14667, 
        -902421, NA, NA, -117535, -2119, -62998, -16900, -599253), 
            `12/31/2014` = c(-577820, 192965, 634603, -177583, 18059, 
            NA, -42451, 81796, -201630, -719423, -12742, -1097272, 
            NA, NA, 1785865, -148150, 1691722, -6532, 669714)), .Names = c("12/31/2017", 
        "12/31/2016", "12/31/2015", "12/31/2014"), row.names = c("Net Income", 
        "Depreciation", "Adjustments To Net Income", "Changes In Accounts Receivables", 
        "Changes In Liabilities", "Changes In Inventories", "Changes In Other Operating Activities", 
        "Total Cash Flow From Operating Activities", "Capital Expenditures", 
        "Investments", "Other Cash flows from Investing Activities", 
        "Total Cash Flows From Investing Activities", "Dividends Paid", 
        "Sale Purchase of Stock", "Net Borrowings", "Other Cash Flows from Financing Activities", 
        "Total Cash Flows From Financing Activities", "Effect Of Exchange Rate Changes", 
        "Change In Cash and Cash Equivalents"), class = "data.frame")), .Names = c("IS", 
    "BS", "CF"))

符号的保存方式如下:

MSFT.f <- structure(list(IS = structure(list(`6/30/2018` = c(110360000, 
38353000, 72007000, 14726000, 22223000, NA, NA, 75302000, 35058000, 
1416000, 35058000, -2733000, 36474000, 19903000, NA, 16571000, 
NA, NA, NA, NA, 16571000, NA, 16571000), `6/30/2017` = c(96571000, 
33850000, 62721000, 12292000, 18807000, NA, NA, 64949000, 31622000, 
-1721000, 31622000, -2222000, 29901000, 4412000, NA, 25489000, 
NA, NA, NA, NA, 25489000, NA, 25489000), `6/30/2016` = c(91154000, 
32780000, 58374000, 11988000, 19198000, NA, NA, 63966000, 27188000, 
-1549000, 27188000, -1243000, 25639000, 5100000, NA, 20539000, 
NA, NA, NA, NA, 20539000, NA, 20539000), `6/30/2015` = c(93580000, 
33038000, 60542000, 12046000, 20324000, NA, NA, 65408000, 28172000, 
-9665000, 28172000, -781000, 18507000, 6314000, NA, 12193000, 
NA, NA, NA, NA, 12193000, NA, 12193000)), .Names = c("6/30/2018", 
"6/30/2017", "6/30/2016", "6/30/2015"), row.names = c("Total Revenue", 
"Cost of Revenue", "Gross Profit", "Research Development", "Selling General and Administrative", 
"Non Recurring", "Others", "Total Operating Expenses", "Operating Income or Loss", 
"Total Other Income/Expenses Net", "Earnings Before Interest and Taxes", 
"Interest Expense", "Income Before Tax", "Income Tax Expense", 
"Minority Interest", "Net Income From Continuing Ops", "Discontinued Operations", 
"Extraordinary Items", "Effect Of Accounting Changes", "Other Items", 
"Net Income", "Preferred Stock And Other Adjustments", "Net Income Applicable To Common Shares"
), class = "data.frame"), BS = structure(list(`6/30/2018` = c(11946000, 
121723000, 26481000, 2662000, 6850000, 169662000, 1862000, 36146000, 
35683000, 8053000, NA, 7442000, 1369000, 258848000, 8617000, 
87508000, 38195000, 58488000, 77810000, 35707000, NA, NA, NA, 
176130000, NA, NA, NA, 71223000, 13682000, -2187000, NA, -2187000, 
82718000, 38982000), `6/30/2017` = c(7663000, 125238000, 22431000, 
2181000, 5183000, 162696000, 6023000, 30289000, 35122000, 10106000, 
NA, 6076000, 248000, 250312000, 7390000, 95527000, 30879000, 
55745000, 81445000, 22986000, NA, NA, NA, 162601000, NA, NA, 
NA, 69315000, 17769000, 627000, NA, 627000, 87711000, 42483000
), `6/30/2016` = c(6510000, 106531000, 18277000, 2251000, 6091000, 
139660000, 10438000, 18356000, 17872000, 3733000, NA, 3409000, 
219000, 193468000, 6898000, 54541000, 33972000, 59357000, 40557000, 
20796000, NA, NA, NA, 121471000, NA, NA, NA, 68178000, 2282000, 
1537000, NA, 1537000, 71997000, 50392000), `6/30/2015` = c(5595000, 
90796000, 17908000, 2902000, 5596000, 122797000, 12053000, 14731000, 
16939000, 4835000, NA, 3117000, 228000, 174472000, 6591000, 35384000, 
30384000, 49647000, 27808000, 16934000, NA, NA, NA, 94389000, 
NA, NA, NA, 68465000, 9096000, 2522000, NA, 2522000, 80083000, 
58309000)), .Names = c("6/30/2018", "6/30/2017", "6/30/2016", 
"6/30/2015"), row.names = c("Cash And Cash Equivalents", "Short Term Investments", 
"Net Receivables", "Inventory", "Other Current Assets", "Total Current Assets", 
"Long Term Investments", "Property Plant and Equipment", "Goodwill", 
"Intangible Assets", "Accumulated Amortization", "Other Assets", 
"Deferred Long Term Asset Charges", "Total Assets", "Accounts Payable", 
"Short/Current Long Term Debt", "Other Current Liabilities", 
"Total Current Liabilities", "Long Term Debt", "Other Liabilities", 
"Deferred Long Term Liability Charges", "Minority Interest", 
"Negative Goodwill", "Total Liabilities", "Misc. Stocks Options Warrants", 
"Redeemable Preferred Stock", "Preferred Stock", "Common Stock", 
"Retained Earnings", "Treasury Stock", "Capital Surplus", "Other Stockholder Equity", 
"Total Stockholder Equity", "Net Tangible Assets"), class = "data.frame"), 
    CF = structure(list(`6/30/2018` = c(16571000, 9900000, -3108000, 
    -3862000, 7070000, -465000, -459000, 43884000, -11632000, 
    6557000, -98000, -6061000, -12699000, NA, -10201000, -971000, 
    -33590000, 50000, 4283000), `6/30/2017` = c(25489000, 7800000, 
    1287000, -1216000, 3901000, 50000, 349000, 39507000, -8129000, 
    -12511000, -197000, -46781000, -11845000, NA, 31459000, -190000, 
    8408000, 19000, 1153000), `6/30/2016` = c(20539000, 5878000, 
    6229000, 562000, 2653000, 6e+05, -2907000, 33325000, -8343000, 
    -14417000, 203000, -23950000, -11006000, NA, 18283000, -369000, 
    -8393000, -67000, 915000), `6/30/2015` = c(12193000, 5400000, 
    10483000, 1456000, -1054000, -272000, 1383000, 29668000, 
    -5944000, -12868000, -466000, -23001000, -9882000, NA, 13661000, 
    362000, -9668000, -73000, -3074000)), .Names = c("6/30/2018", 
    "6/30/2017", "6/30/2016", "6/30/2015"), row.names = c("Net Income", 
    "Depreciation", "Adjustments To Net Income", "Changes In Accounts Receivables", 
    "Changes In Liabilities", "Changes In Inventories", "Changes In Other Operating Activities", 
    "Total Cash Flow From Operating Activities", "Capital Expenditures", 
    "Investments", "Other Cash flows from Investing Activities", 
    "Total Cash Flows From Investing Activities", "Dividends Paid", 
    "Sale Purchase of Stock", "Net Borrowings", "Other Cash Flows from Financing Activities", 
    "Total Cash Flows From Financing Activities", "Effect Of Exchange Rate Changes", 
    "Change In Cash and Cash Equivalents"), class = "data.frame")), .Names = c("IS", 
"BS", "CF"))

所以我想知道如何通过3个名为symbols.f <- c("MSFT.f", "TWTR.f") symbolsIS的excel选项卡将所有符号保存在BS中。

1 个答案:

答案 0 :(得分:0)

我建议您使用xlsx软件包。使用此软件包,您可以编辑excel文件的选定选项卡/工作表来解决您的任务,如下所示:

library("xlsx")
for (name in names(MSFT.f))
  xlsx::write.xlsx(x = MSFT.f[[name]],
                   file = "MSFT.xlsx", 
                   sheetName = name,
                   append = TRUE)
for (name in names(TWTR.f))
  xlsx::write.xlsx(x = TWTR.f[[name]],
                   file = "TWTR.xlsx", 
                   sheetName = name,
                   append = TRUE)