R 将固定宽度列写入 csv(在纯文本文件中)
我使用 write.csv() 将数据帧写入 csv 文件。完成此操作后,在纯文本编辑器(特别是 vi 或 notepad++)中查看输出时,列内容和逗号之间没有间距,导致其相对难以阅读。例如,各列没有在页面上排列。
我对使用 Excel 查看 csv 文件不感兴趣。我绝对不是在寻找 csv 查看器的建议。我也不需要有关如何修改纯文本文件的说明。填充必须是空格而不是制表符。
我对如何让 R 排列纯文本 csv 文件中的列感兴趣,以便使用非专用纯文本编辑器更容易阅读它们。
我可以(并且可能)编写自己的将所有内容转换为某种固定宽度字符串格式并打印的例程。但是,我更愿意发现这是 write.csv() 或类似的常见输出库调用中的一个选项。
[我刚刚在 R 中发现了 printf,这可能是这个难题的最佳答案]。
I write data frames to csv files using write.csv(). When this is done, the output when viewed in a plain text editor, in particular vi or notepad++, shows no spacing between the column content and the commas, resulting in it being relatively hard to read. For example, the columns are not lined up down the page.
I have negative interest in using excel to view the csv files. I am definitely not looking for a suggestion for a csv viewer. Nor do I want instructions on how to modify the plain text file afterward. Padding needs to be spaces not tabs.
I am interested in how to get R to line up the columns in the plain text csv file so that they are easier to read using a non specialized plain text editor.
I could (and might) write my own routine that converts everything to some fixed width string format and print that. But, I would prefer to find that this is an option within write.csv() or similar common output library call.
[I just this moment found out about printf in R, and that might be the best answer to this conundrum].
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论