Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Number formatting in concatenation of sqldf in R

I would like to understand the formatting, which is applied to a number, which is included in a concatenated string in sqldf.
I would like to know how one could replicate the output with base R, so basically it rounds to 0 digits, but prints out the first digit nonetheless.

library(sqldf)
sqldf("SELECT (' - tx: '||round(2152.918349)) as test")
           test
1  - tx: 2153.0

If I would just round this number using R without sqldf, it would just be printed out as an integer.

 print(round(2152.918349))
 [1] 2153

So most probably sqldf applies some additional formatting on the number, but I could not find any documentation on what exactly it is doing there.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

For base R to print the same number as sqldf, use sprintf:

sprintf("%.1f", round(2152.918349))

# [1] "2153.0"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading