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 3 months 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 • 142 views
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.

0
Entering edit mode
@james-w-macdonald-5106
Last seen 21 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?

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.