What's the difference between formatC() and round() function when used to limite digits numbers?
1
0
Entering edit mode
Yang • 0
@6064fd3a
Last seen 2.5 years ago
Hong Kong

I use the code below, and use ifelse() to judge whether they are equal. But unique output A and B. Is that mean BHf and BH_round are different? Why they r different?

#output$BHf <- formatC(output$BH,digits = 9,format = "f")
#output$BH_round <- output$BH,digits = 9)
#output$result<- ifelse(output$BHf==output$BH_round,'A','B')
#unique(xinipian_lnc_adjustP_output_oue$result)
round formatC • 655 views
ADD COMMENT
0
Entering edit mode

I have changed identical() to find if there is any difference between BHf and BH_round. The output of identical() is false. That means BHf and BH_round are different.

ADD REPLY
0
Entering edit mode
@james-w-macdonald-5106
Last seen 4 hours ago
United States

This question isn't Bioconductor specific, so should be directed to r-help@r-project.org. But that probably won't go over very well, and you are likely to get RTFM'ed pretty hard. Which, fair enough. You could read the manual or just do a test, like for example

> formatC(pi, 3, format = "f")
[1] "3.142"
> round(pi, 3)
[1] 3.142

## And

> notpi <- 3.1415690450450340580489543
> all.equal(round(notpi, 9), as.numeric(formatC(notpi, 9, format = "f")))
[1] TRUE

Which I think explains things pretty well?

ADD COMMENT
0
Entering edit mode

Thanks! I have checked it and found all.equal(output$BHf, output$BH_round) output TRUE., while identical(output$BHf, output$BH_round) output FALSE. Equal() and identical() are different in identifying 2 values.

ADD REPLY

Login before adding your answer.

Traffic: 704 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6