读者:在write

编程入门 行业动态 更新时间:2024-10-14 14:15:19
本文介绍了读者:在write_csv中关闭科学计数法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用R处理人口普查数据,该数据使用了很长的数字GEOID来标识地理位置.我面临的问题是,当使用write_csv(来自readr包)写出处理过的数据时,它正在以科学计数法编写这些GEOID.有办法解决这个问题吗?

I am using R to process Census data which uses really long numeric GEOIDs to identify the geographies. The issue I am facing is when writing out the processed data using write_csv (from the readr package) it is writing these GEOIDs in scientific notation. Is there a way to get around this?

注意:通过将scipen选项设置为足够大的值,我可以在R控制台上切换科学计数法显示.但是此设置似乎没有扩展到readr库中.

Note: I am able to toggle scientific notation display on R console using by setting the scipen option to a sufficiently large value. But this setting does not seem to extend into the readr library.

这是一个玩具数据集:

library(dplyr) library(readr) # which is the package with write_csv (tbl_df(data.frame(GEOID = seq(from=60150001022000, to=60150001022005, 1)))) Source: local data frame [6 x 1] GEOID 1 60150001022000 2 60150001022001 3 60150001022002 4 60150001022003 5 60150001022004 6 60150001022005 write_csv((tbl_df(data.frame(GEOID = seq(from=60150001022000, to=60150001022005, 1)))), "test.csv")

这就是我目前正在得到的.我正在寻找一种获得与上述相同数字的方法:

This is what I am getting currently. I am looking for a way to get the same numbers as above:

GEOID 6.02E+13 6.02E+13 6.02E+13 6.02E+13 6.02E+13 6.02E+13

推荐答案

我宁愿建议将此类列重新编码为int,因为如果这样,write_*将不再使用科学数字编码.要一次转换所有数字列(例如,如果要处理计数矩阵),可以执行以下操作:

I'd rather suggest recoding such columns to type int, because if so write_* won't use scientific number encoding anymore. To convert all numeric columns in one pass (e.g. in case you're dealing with a counts matrix), you could do:

require(dplyr) tbl_df = mutate_if(tbl_df, is.numeric, as.integer)

更多推荐

读者:在write

本文发布于:2023-05-28 06:58:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/315160.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:读者   write

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!