如何在R中正确写入csv或文本文件

时间:2019-03-08 17:27:57

标签: r

我正在尝试在R中保存一个csv文件或文本文件。

一栏包含段落,其中有逗号,因此在我写时;

write.table(x, file = "D:/text.csv", sep = ",", row.names = FALSE)

y <- read.csv(file = "D:/text.csv")

它写入文件,但是当我读入文件时,从50行增加到57行。我知道这可能是由于sep = ","参数引起的,我可以将其更改为“ |”但是这些文件确实很大,并且文本列可能包含许多不同的字符,无法使用sep来工作。

我该如何克服这个问题?

数据:

x <- structure(list(Document = c("https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.1", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.2", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.3", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.4", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.5", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.6", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.7", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.8", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.9", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.10", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.11", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.12", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.13", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.14", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.15", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.16", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.17", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.18", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.19", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.20", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.21", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.22", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.23", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.24", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.25", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.26", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.27", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.28", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.29", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.30", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.31", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.32", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.33", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.34", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.35", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.36", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.37", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.38", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.39", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.40", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.41", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.42", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.43", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.44", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.45", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.46", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.47", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.48", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.49", 
"https://www.sec.gov/Archives/edgar/data/718877/000104746916010584/a2227483z10-k.htm.50"
), text = c("Use these links to rapidly review the document    TABLE OF CONTENTS     Item 8. FINANCIAL STATEMENTS AND SUPPLEMENTARY DATA", 
"Table of Contents", "UNITED STATES  SECURITIES AND EXCHANGE COMMISSION   Washington, D.C. 20549", 
"FORM 10-K", "(Mark one)      ý     ANNUAL REPORT PURSUANT TO SECTION 13 OR 15(d) OF THE SECURITIES EXCHANGE ACT OF 1934   For the Fiscal Year Ended December 31, 2015   OR  o     TRANSITION REPORT PURSUANT TO SECTION 13 OR 15(d) OF THE SECURITIES EXCHANGE ACT OF 1934   For the transition period from                                to", 
"Commission File Number 1-15839", "ACTIVISION BLIZZARD, INC.   (Exact name of registrant as specified in its charter)", 
"Delaware  (State or other jurisdiction of incorporation or organization)    95-4803544  (I.R.S. Employer Identification No.)  3100 Ocean Park Boulevard, Santa Monica, CA  (Address of principal executive offices)      90405  (Zip Code)", 
"Registrant's telephone number, including area code: (310) 255-2000", 
"Securities registered pursuant to Section 12(b) of the Act:", 
"Title of each Class    Name of Each Exchange on Which Registered  Common Stock, par value $.000001 per share   The NASDAQ Global Select Market", 
"Securities registered pursuant to Section 12(g) of the Act:  None", 
"Indicate by check mark if the registrant is a well-known seasoned issuer, as defined in Rule 405 of the Securities Act. Yes ý No o", 
"Indicate by check mark if the registrant is not required to file reports pursuant to Section 13 or Section 15 (d) of the Act. Yes o No ý", 
"Indicate by check mark whether the registrant (1) has filed all reports required to be filed by Section 13 or 15(d) of the Securities Exchange Act of 1934 during the preceding 12 months (or for such shorter period that the registrant was required to file such reports), and (2) has been subject to such filing requirements for the past 90 days. Yes ý No o", 
"Indicate by check mark whether the registrant has submitted electronically and posted on its corporate Web site, if any, every Interactive Data File required to be submitted and posted pursuant to Rule 405 of Regulation S-T (§ 232.405 of this chapter) during the preceding 12 months (or for such shorter period that the registrant was required to submit and post such files). Yes ý No o", 
"Indicate by check mark if disclosure of delinquent filers pursuant to Item 405 of Regulation S-K is not contained herein, and will not be contained, to the best of the registrant's knowledge, in definitive proxy or information statements incorporated by reference in Part III of this Form 10-K or any amendment to this Form 10-K. ý", 
"Indicate by check mark whether the registrant is a large accelerated filer, an accelerated filer, a non-accelerated filer, or a smaller reporting company. See the definitions of \"large accelerated filer,\" \"accelerated filer,\" and \"smaller reporting company\" in Rule 12b-2 of the Exchange Act.", 
"Large Accelerated Filer ý   Accelerated Filer o   Non-accelerated Filer o  (Do not check if a  smaller reporting company)   Smaller Reporting Company o", 
"Indicate by check mark whether the registrant is a shell company (as defined in Rule 12b-2 of the Act). Yes o No ý", 
"The aggregate market value of the registrant's Common Stock held by non-affiliates on June 30, 2015 (based on the closing sale price as reported on the NASDAQ) was $13,345,675,247.", 
"The number of shares of the registrant's Common Stock outstanding at February 22, 2016 was 734,998,115.", 
"Documents Incorporated by Reference", "Portions of the registrant's definitive Proxy Statement, to be filed with the Securities and Exchange Commission with respect to the 2016 Annual Meeting of Shareholders which is expected to be held on June 2, 2016, are incorporated by reference into Part III of this Annual Report.", 
"Table of Contents", "ACTIVISION BLIZZARD, INC. AND SUBSIDIARIES        Table of Contents", 
"Page No.  PART I.    3     Cautionary Statement   3  Item 1.   Business      Item 1A.   Risk Factors   15  Item 1B.   Unresolved Staff Comments   40  Item 2.   Properties   40  Item 3.   Legal Proceedings   40  Item 4.   Mine Safety Disclosures   41 PART II.    42  Item 5.   Market for Registrant's Common Equity, Related Stockholder Matters, and Issuer Purchases of Equity Securities   42  Item 6.   Selected Financial Data   45  Item 7.   Management's Discussion and Analysis of Financial Condition and Results of Operations   46  Item 7A.   Quantitative and Qualitative Disclosures about Market Risk   83  Item 8.   Financial Statements and Supplementary Data   86  Item 9.   Changes in and Disagreements with Accountants on Accounting and Financial Disclosure   86  Item 9A.   Controls and Procedures   86  Item 9B.   Other Information   87 PART III.    88  Item 10.   Directors, Executive Officers, and Corporate Governance   88  Item 11.   Executive Compensation   88  Item 12.   Security Ownership of Certain Beneficial Owners and Management and Related Stockholder Matters   88  Item 13.   Certain Relationships and Related Transactions, and Director Independence   88  Item 14.   Principal Accounting Fees and Services   88 PART IV.    89  Item 15.   Exhibits, Financial Statement Schedule   89 SIGNATURES   90 Exhibit Index   E-1", 
"2", "Table of Contents", "PART I", "CAUTIONARY STATEMENT", "This Annual Report on Form 10-K contains, or incorporates by reference, certain forward-looking statements within the meaning of the Private Securities Litigation Reform Act of 1995. Such statements consist of any statement other than a recitation of historical facts and include, but are not limited to: (1) projections of revenues, expenses, income or loss, earnings or loss per share, cash flow or other financial items; (2) statements of our plans and objectives, including those relating to product releases; (3) statements of future financial or operating performance; (4) statements relating to the acquisition of King Digital Entertainment plc and expected impact of that transaction, including without limitation, the expected impact on Activision Blizzard's future financial results; and (5) statements of assumptions underlying such statements. Activision Blizzard, Inc. generally uses words such as \"outlook,\" \"forecast,\" \"will,\" \"could,\" \"should,\" \"would,\" \"to be,\" \"plan,\" \"plans,\" \"believes,\" \"may,\" \"might,\" \"expects,\" \"intends,\" \"intends as,\" \"anticipates,\" \"estimate,\" \"future,\" \"positioned,\" \"potential,\" \"project,\" \"remain,\" \"scheduled,\" \"set to,\" \"subject to,\" \"upcoming\" and other similar expressions to help identify forward-looking statements. Forward-looking statements are subject to business and economic risks, reflect management's current expectations, estimates and projections about our business, and are inherently uncertain and difficult to predict. Our actual results could differ materially from expectations stated in forward-looking statements. Some of the risk factors that could cause our actual results to differ from those stated in forward-looking statements can be found in \"Risk Factors\" included in Part I, Item 1A of this Report. The forward-looking statements contained herein are based upon information available to us as of the date of this Annual Report on Form 10-K and we assume no obligation to update any such forward-looking statements. Although these forward-looking statements are believed to be true when made, they may ultimately prove to be incorrect. These statements are not guarantees of our future performance and are subject to risks, uncertainties and other factors, some of which are beyond our control and may cause actual results to differ materially from current expectations.", 
"Activision Blizzard Inc.'s names, abbreviations thereof, logos, and product and service designators are all either the registered or unregistered trademarks or trade names of Activision Blizzard. All other product or service names are the property of their respective owners.", 
"Overview", "Activision Blizzard, Inc. is a worldwide developer and publisher of online, personal computer (\"PC\"), video game console, handheld, mobile and tablet games. The terms \"Activision Blizzard,\" the \"Company,\" \"we,\" \"us,\" and \"our\" are used to refer collectively to Activision Blizzard, Inc. and its subsidiaries. We currently offer games that operate on the Microsoft Corporation (\"Microsoft\") Xbox One (\"Xbox One\") and Xbox 360 (\"Xbox 360\"), Nintendo Co. Ltd. (\"Nintendo\") Wii U (\"Wii U\") and Wii (\"Wii\"), and Sony Computer Entertainment Inc. (\"Sony\") PlayStation 4 (\"PS4\") and PlayStation 3 (\"PS3\") console systems (Xbox One, Wii U, and PS4 are collectively referred to as \"next-generation\"; Xbox 360, Wii, and PS3 are collectively referred to as \"prior-generation\"); the PC; the Nintendo 3DS, Nintendo Dual Screen and Sony PlayStation Vita handheld game systems; and mobile and tablet devices.", 
"Activision - Through Activision Publishing, Inc. (\"Activision\"), we are a leading international developer and publisher of interactive software products and content. Activision develops, markets and sells products through retail channels or digital downloads, which are principally based on our internally developed intellectual properties, as well as some licensed properties. Activision delivers content to a broad range of gamers, ranging from children to adults, and from core gamers to mass-market consumers to \"value\" buyers seeking budget-priced software, in a variety of geographies. Activision continues to focus its efforts in the areas we believe have the most opportunity for growth and higher profitability, while reducing investments in areas we believe have less profit potential and", 
"3", "Table of Contents", "limited growth opportunities. To that end, investments are focused on proven intellectual properties to develop deep, high-quality content that offers engaging online gaming experiences. One of Activision's leading franchises is Call of Duty®, which launched in 2003, and has been the best-selling Western interactive franchise since its launch. In 2015, Activision released the latest installment in the franchise, Call of Duty: Black Ops III, which, according to The NPD Group, GfK Chart-Track, and Activision Blizzard internal estimates, was the #1 best-selling console game globally in 2015. Activision is currently developing, distributing, and selling additional digital content for the global community of  Call of Duty: Black Ops III players, along with content for the other Call of Duty titles, in addition to developing future releases and sequels.", 
"Another leading franchise for Activision is Skylanders®, which launched in 2011 with the release of Skylanders Spyro's Adventure. Games in the Skylanders franchise combine the use of physical toys with digital interactive experiences to deliver innovative gameplay to our audience. In September 2015, we released Skylanders SuperChargers, which introduced vehicles-to-life - an entirely new way for fans to experience the magic of Skylanders.", 
"While focusing on proven intellectual properties is one of Activision's priorities, we also continue to make strategic investments in developing new intellectual properties that we believe have the potential for long-term growth and success. For example, on September 15, 2015, we released The Taken King, the third and largest expansion to Destiny, the game universe created by Bungie under our long-term alliance with them. We also introduced microtransactions within  Destiny in October 2015 and expect to release additional content to our global community of Destiny players in 2016.", 
"Blizzard - Blizzard Entertainment, Inc. (\"Blizzard\") is a leader in online PC gaming, including the subscription-based massively multi-player online role-playing game (\"MMORPG\") category in terms of both subscriber base and revenues generated through its World of Warcraft® franchise. Blizzard also develops, markets, and sells role-playing action and strategy games for the PC, console, mobile and tablet platforms, including games in the multiple-award winning Diablo®, StarCraft®, Hearthstone®: Heroes of Warcraft<U+0099> and Heroes of the Storm<U+0099> franchises. In addition, Blizzard maintains a proprietary online gaming service, Battle.net®, which facilitates the creation of user-generated content, digital distribution and online social connectivity across all Blizzard games. Blizzard distributes its products and generates revenues worldwide through various means, including: subscriptions; sales of prepaid subscription cards; in-game purchases and services; retail sales of physical \"boxed\" products; online download sales of PC products; purchases and downloads via third-party console, mobile and tablet platforms; and licensing of software to third-party or related party companies that distribute Blizzard products.", 
"Blizzard has released five expansion packs to the epic World of Warcraft franchise since 2004, with the most recent release, World of Warcraft: Warlords of Draenor®, having been released in November 2014, and the next expansion, World of Warcraft: Legion<U+0099>, to be released in the summer of 2016. For Hearthstone: Heroes of Warcraft, in addition to bringing the game to iOS and Android smartphones in April 2015, three new content releases, Blackrock Mountain<U+0099>, The Grand Tournament<U+0099>, and  The League of Explorers<U+0099>, were introduced in 2015 and have continued to drive performance.", 
"Blizzard continues to invest in new opportunities, both by leveraging its internally developed intellectual property, such as the release of Heroes of the Storm in 2015, as well as developing new intellectual property with the upcoming team-based first person shooter,  Overwatch<U+0099>, which is expected to be released commercially in the spring of 2016.", 
"Other - We also engage in other business opportunities including:", 
"<U+0095> The Activision Blizzard Media Networks (\"Media Networks\") business, announced in 2015, which builds on our efforts in competitive gaming and the growing eSports industry;", 
"4", "Table of Contents", "<U+0095> The Activision Blizzard Studios (\"Studios\") business, announced in 2015, which is devoted to creating original film and television content based on the company's extensive library of iconic and globally-recognized intellectual properties; and    <U+0095> The Activision Blizzard Distribution (\"Distribution\") business, which consists of operations in Europe that provide warehousing, logistical, and sales distribution services to third-party publishers of interactive entertainment software, our own publishing operations, and manufacturers of interactive entertainment hardware.", 
"Revenues associated with the Call of Duty, World of Warcraft, Skylanders, and Destiny franchises combined accounted for 71%, 72%, and 80% of our consolidated net revenues for the years ended December 31, 2015, 2014, and 2013, respectively."
), part.name = c("", "", "", "", "", "", "", "", "", "", "", 
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 
"", "", "PART I", "PART I", "PART I", "PART I", "PART I", "PART I", 
"PART I", "PART I", "PART I", "PART I", "PART I", "PART I", "PART I", 
"PART I", "PART I", "PART I", "PART I", "PART I", "PART I", "PART I", 
"PART I"), item.name = c("", "", "", "", "", "", "", "", "", 
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 
"", "", "", "", "", "", "", "", ""), Documentshort = c("a2227483z10-k", 
"a2227483z10-k", "a2227483z10-k", "a2227483z10-k", "a2227483z10-k", 
"a2227483z10-k", "a2227483z10-k", "a2227483z10-k", "a2227483z10-k", 
"a2227483z10-k", "a2227483z10-k", "a2227483z10-k", "a2227483z10-k", 
"a2227483z10-k", "a2227483z10-k", "a2227483z10-k", "a2227483z10-k", 
"a2227483z10-k", "a2227483z10-k", "a2227483z10-k", "a2227483z10-k", 
"a2227483z10-k", "a2227483z10-k", "a2227483z10-k", "a2227483z10-k", 
"a2227483z10-k", "a2227483z10-k", "a2227483z10-k", "a2227483z10-k", 
"a2227483z10-k", "a2227483z10-k", "a2227483z10-k", "a2227483z10-k", 
"a2227483z10-k", "a2227483z10-k", "a2227483z10-k", "a2227483z10-k", 
"a2227483z10-k", "a2227483z10-k", "a2227483z10-k", "a2227483z10-k", 
"a2227483z10-k", "a2227483z10-k", "a2227483z10-k", "a2227483z10-k", 
"a2227483z10-k", "a2227483z10-k", "a2227483z10-k", "a2227483z10-k", 
"a2227483z10-k"), companyID = c("718877", "718877", "718877", 
"718877", "718877", "718877", "718877", "718877", "718877", "718877", 
"718877", "718877", "718877", "718877", "718877", "718877", "718877", 
"718877", "718877", "718877", "718877", "718877", "718877", "718877", 
"718877", "718877", "718877", "718877", "718877", "718877", "718877", 
"718877", "718877", "718877", "718877", "718877", "718877", "718877", 
"718877", "718877", "718877", "718877", "718877", "718877", "718877", 
"718877", "718877", "718877", "718877", "718877")), .Names = c("Document", 
"text", "part.name", "item.name", "Documentshort", "companyID"
), row.names = c(NA, 50L), class = "data.frame")

2 个答案:

答案 0 :(得分:3)

首先将文件转换为<link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/xml-js@1.6.11/dist/xml-js.min.js"></script> <script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js"></script> <div id="map"></div>,然后尝试

data.frame

然后文件将存储在您的工作目录中

答案 1 :(得分:1)

怎么样?

library(data.table)
fwrite(as.data.table(x), "text.csv")

使用fread()将其读回。