[英]How to export text from R into one cell in Excel
I have 3205 observations in my dataset.我的数据集中有 3205 个观察值。 Each observation contains several paragraphs worth of text and looks something like this:每个观察都包含几段文字,看起来像这样:
BRIEF_ID Brief_ID | STATE状态 | BRIEF简短的 |
---|---|---|
01999110036250 01999110036250 | ALABAMA阿拉巴马州 | paragraphs of text here...这里的文字段落... |
My goal is to export this dataset into Excel/csv so that it looks exactly like it does in R. So far I've tried different variations of this:我的目标是将此数据集导出到 Excel/csv 中,使其看起来与 R 中的完全一样。到目前为止,我已经尝试了不同的变体:
write.table(MyData, file="MyData.csv", sep=",")
Unfortunately, when I use this syntax, it exports into Excel/csv in a very weird way, splitting the paragraphs of text into multiple columns and multiple rows.不幸的是,当我使用这种语法时,它以一种非常奇怪的方式导出到 Excel/csv 中,将文本段落分成多列和多行。 For example例如
BRIEF_ID Brief_ID | STATE状态 | BRIEF简短的 | |
---|---|---|---|
01999110036250 01999110036250 | ALABAMA阿拉巴马州 | paragraphs段落 | text文本 |
of的 | |||
here...这里... |
Any idea how I can keep the paragraphs of text together in one cell?知道如何将文本段落保存在一个单元格中吗?
UPDATED TEXT/NOTEPAD EXAMPLE FOR 1 OBSERVATION * 1 次观察的更新文本/记事本示例*
41,' ' 0499970019131,ARIZONA,"GOOD AFTERNOON EVERYONE., THANK YOU FOR BEING HERE TODAY., AND I WANT TO UPDATE YOU ON WHERE ARIZONA IS IN ITS CURRENT SITUATION, WHERE OUR NUMBERS, ARE, AND THE ACTION STEPS WE INTEND TO TAKE GOING FORWARD., I WANT TO BEGIN BY JUST AGAIN SAYING THANK YOU TO ALL OF OUR NURSES, DOCTORS, EMERGENCY, MEDICAL RESPONDERS, AND HEALTHCARE WORKERS, T",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, DAY THAT WE ARE DEFINITELY,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 41,' ' 0499970019131,亚利桑那州,“大家下午好。感谢您今天来到这里。我想向您介绍亚利桑那州目前的情况,我们的人数,以及我们打算采取的行动步骤继续前进。我想再次向我们所有的护士、医生、急救人员、医疗急救人员和卫生保健工作者说声谢谢,T",,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 天我们绝对是,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,
Well, supposing you have a dataframe data
in memory, then:好吧,假设您在内存中有一个数据帧data
,那么:
# run install.packages("writexl") to install it
writexl::write_xlsx(data, "my_data.xlsx")
write_xlsx will probably help but from the CSV posted I think the issue is parsing. write_xlsx 可能会有所帮助,但从发布的 CSV 来看,我认为问题正在解析。 The csv sample gets imported mostly intact in Excel 365 in that the main paragraph is in a single cell on my machine so it must be some CSV / local setting on your end while importing. csv 样本在 Excel 365 中几乎完整地导入,因为主要段落位于我机器上的单个单元格中,因此在导入时它必须是您端的一些 CSV/本地设置。
Working with CSV for large amounts of unstructured text that has commas can cause a lot of strange issues.使用 CSV 处理大量带有逗号的非结构化文本可能会导致很多奇怪的问题。 I would change the separator to |我会将分隔符更改为 | or something even less commonly used by humans.或者人类更不常用的东西。 Then import it using Excel Power Query by opening a blank workbook and selecting "Get Data -> Text/CSV" under the data tab and telling it what delimiter you used.然后使用 Excel Power Query 导入它,方法是打开一个空白工作簿并在数据选项卡下选择“获取数据 -> 文本/CSV”并告诉它您使用的分隔符。 You can also specify the csv format in the power query import although excel takes a good guess.您也可以在 power 查询导入中指定 csv 格式,尽管 excel 可以很好地猜测。
Also it may be stating the obvious but those rows of ,,,,,, will translate into blank columns, I am assuming that is intended if not then there may be an issue with how the data is structured for export.此外,它可能说明了显而易见的问题,但 ,,,,,, 的那些行将转换为空白列,我假设这是有意的,如果不是这样,那么数据的导出结构可能存在问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.