由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - round问题
相关主题
大家习惯round(2.5)=3还是2?about first round phone interview with Amazon for business (转载)
a R questionR: 'ada' Package - how to see its source code?
R里为什么3.1+2.7==5.8是false?请教如何在一数列中找出某个数值的最长连续个数
求救,一个关于血型的概率问题请问contractor的工作是不是可以随时反悔
round function请问哪里能下载R.h文件.
###### 问个SAS存贮,显示数据的问题问个SAS regression问题
sas base questioncould anybody please help check why my codes don't work? Thanks!
刚接到BOA的first round thingy问一个统计弱问题
相关话题的讨论汇总
话题: round话题: true话题: even话题: result话题: happened
进入Statistics版参与讨论
1 (共1页)
G***G
发帖数: 16778
1
【 以下文字转载自 Programming 讨论区 】
发信人: GoooG (pumpkin), 信区: Programming
标 题: round问题
发信站: BBS 未名空间站 (Sat Nov 29 14:46:09 2014, 美东)
round(2.5) =2
round(3.5) =4
this happened in R.
why?
l******t
发帖数: 96
2
# Round to nearest, with .5 values rounded to even number.

【在 G***G 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 发信人: GoooG (pumpkin), 信区: Programming
: 标 题: round问题
: 发信站: BBS 未名空间站 (Sat Nov 29 14:46:09 2014, 美东)
: round(2.5) =2
: round(3.5) =4
: this happened in R.
: why?

G***G
发帖数: 16778
3
in R which function can round 'not to even'?
have you checked the following one?
(0.1+0.05)>0.15
The stupid R gives 'TRUE' as answer.

【在 l******t 的大作中提到】
: # Round to nearest, with .5 values rounded to even number.
D******n
发帖数: 2836
4
我好像以前碰到过这个问题,一气之下自己写了个round function。
R的base经常缺乏一些最基本的functions,很让人头痛。

【在 G***G 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 发信人: GoooG (pumpkin), 信区: Programming
: 标 题: round问题
: 发信站: BBS 未名空间站 (Sat Nov 29 14:46:09 2014, 美东)
: round(2.5) =2
: round(3.5) =4
: this happened in R.
: why?

l******t
发帖数: 96
5
it's not about R, it's how floating number is represented in computer.
Even you typed the same equation and get True in Python.

【在 G***G 的大作中提到】
: in R which function can round 'not to even'?
: have you checked the following one?
: (0.1+0.05)>0.15
: The stupid R gives 'TRUE' as answer.

G***G
发帖数: 16778
6
does this exist in other language such as C?

【在 l******t 的大作中提到】
: it's not about R, it's how floating number is represented in computer.
: Even you typed the same equation and get True in Python.

l******t
发帖数: 96
7
The result is the same in my test case in C++. I think it's common sense not
to use "=" to compare floating number in programming languages.
#include
using namespace std;
int main() {
bool result = (.1 + .05) > .15;
cout << result;
return 0;
}
g++ test.cpp && ./a.out
1

【在 G***G 的大作中提到】
: does this exist in other language such as C?
G***G
发帖数: 16778
8
interesting.
thanks.

not

【在 l******t 的大作中提到】
: The result is the same in my test case in C++. I think it's common sense not
: to use "=" to compare floating number in programming languages.
: #include
: using namespace std;
: int main() {
: bool result = (.1 + .05) > .15;
: cout << result;
: return 0;
: }
: g++ test.cpp && ./a.out

H*H
发帖数: 472
9
R的本质是数据分析,要是2.5 round 到3, 3.5 round 到4,都比原来大了0.5,得到
的结果就很容易引起bias
要是你想得到你要的结果, 用floor(0.5 + x) 应该就行了
1 (共1页)
进入Statistics版参与讨论
相关主题
问一个统计弱问题round function
怎么把带小数的值ROUND 到整数?###### 问个SAS存贮,显示数据的问题
SAS QUESTIONS: Urgent time formating problem, please help!sas base question
贡献两道面试的概率题。刚接到BOA的first round thingy
大家习惯round(2.5)=3还是2?about first round phone interview with Amazon for business (转载)
a R questionR: 'ada' Package - how to see its source code?
R里为什么3.1+2.7==5.8是false?请教如何在一数列中找出某个数值的最长连续个数
求救,一个关于血型的概率问题请问contractor的工作是不是可以随时反悔
相关话题的讨论汇总
话题: round话题: true话题: even话题: result话题: happened