我正在使用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
发布评论