从R导出大量到csv [英] Exporting large number to csv from R

查看:45
本文介绍了从R导出大量到csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将R数据帧导出到csv文件时遇到一个奇怪的问题.数据帧包含一些大数字,但是当将它们写到csv文件时,它们会丢失"小数部分,而改写时不包含小数部分.但并非像人们期望的那样,而是这样:

I came across a strange problem when trying to export an R dataframe to a csv file. The dataframe contains some big numbers, but when they are written to the csv file, they "lose" the decimal part and are instead written without it. But not like one would expect, but like this:

说3224571816.5649是R中的正确值.当写入csv时,它变为32245718165649.

Say 3224571816.5649 is the correct value in R. When written to csv, it becomes 32245718165649.

我正在使用 write.csv2 函数编写csv.分隔符是正确的,因为它通常适用于较小的值.是由于数字(带小数点)大于32位而引起的吗?

I am using the write.csv2 function to write the csv. The separators are correct, as it works normally for smaller values. Is the problem occurring because the number (with decimals) is bigger than 32bit?

更重要的是,由于我有一个完整的数据框,其值大于或等于此值,我该如何解决呢?另外,还必须将其写入csv.

And more importantly, how can I solve this, as I have a whole dataframe with values as big (or bigger) than this? Also, it has to be written in to a csv.

推荐答案

write.csv2适用于不同的csv标准(西欧样式,根据您使用."作为十进制指示符,我是猜你不是在找).write.csv2使用逗号作为小数点指示符,使用分号作为字段定界符,因此,如果您尝试以逗号分隔的文件形式读取结果,则确实看起来很奇怪.

write.csv2 is intended for a different standard of csv (Western European styling, which based on your use of a "." as a decimal indicator, I am guessing you are not looking for). write.csv2 uses a comma as a decimal indicator and a semicolon as the field delimiter, so if you are trying to read the result in as a comma separated file, it will look strange indeed.

我建议您使用write.csv(甚至更好的是write.table)来输出文件.write.csv假定逗号分隔符和小数点标记的句点.

I suggest you use write.csv (or even better, write.table) to output your file. write.csv assumes a comma separator and period for decimal marker.

write.csv和write.csv2都只是write.table的包装器,后者是基础方法.通常,我建议使用write.table,因为它不会假设您所在的区域,并且您可以显式地将其传递给sep =,",dec =."等.这不仅可以使您确定要使用的内容,但这也使您的代码更具可读性.

both write.csv and write.csv2 are just wrappers for write.table, which is the underlying method. In general, I recommend use of write.table because it does not assume your region and you can explicitly pass it sep = ",", dec = ".", etc. This not only lets you know what you are using for sure, but it also makes your code a lot more readable.

有关更多信息,请访问rdocumentation.org网站上的write.table: https://www.rdocumentation.org/packages/utils/versions/3.5.3/topics/write.table

for more, check the rdocumentation.org site for write.table: https://www.rdocumentation.org/packages/utils/versions/3.5.3/topics/write.table

这篇关于从R导出大量到csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆