Joe*_*Joe 7 r scientific-notation options
我不想在我的R会话中的任何计算结果中看到任何科学记数法.我希望看到所有实际数字,最好在每三个数字后面加一个逗号(,).
我怎样才能做到这一点? options(scipen = 999)不削减它.
42-*_*42- 11
该print.default函数options()['digits']在"决定"要分配的宽度时查看值,因此您可能需要增加它以及尝试最大化"scipen".存在操作系统特定问题,该宽度的值大于16.至于逗号请求,......忘了.R不是财务报告系统.如果你需要强制使用这种输出格式,你可以将对象定义为特定的类,并使用sprintf和formatC为它们编写打印方法,或者我想你可以重写print.default,但这可能只会影响打印操作传递给其他100多种方法之一print.
有输出方法.formatC()并且prettyNum()都有一个'big.mark'参数,可以将逗号插入数字中.输出的"character"格式,这样就不会尝试这样做.在创建结果的任何进一步的计算.
还有一些输入方法可以读取包含逗号或货币符号的数字的列:
setAs("character", "num.with.commas", function(from) as.numeric(gsub(",", "", from)))
setAs("character", "euro",
function(from) as.numeric(gsub("€", "", from)))
setAs("character", "num_pct",
function(from) as.numeric(gsub("%", "", from))/100)
# you will get warning messages if you have not defined the class,
# .... but this will still succeed
Input <- "A B C
1,000 1% 3.50€
2,000 2% 4.77€
3,000 3% €5.68
"
DF <- read.table(textConnection(Input), header = TRUE,
colClasses = c("num.with.commas", "num_pct", "euro"))
str(DF)
Run Code Online (Sandbox Code Playgroud)