Answers for "sprintf R examples"

0

sprintf R examples

sprintf("%06d", 12)		   #  "000012" - leading zeros for 6 digits

x <- 123.456 
sprintf("%f", x)           # "123.456000" - sprintf with default specification 
sprintf("%.10f", x)        # "123.4560000000" - sprintf with ten decimal places
sprintf("%.2f", x)         # "123.46" - sprintf with two rounded decimal places
sprintf("%1.0f", x)        # "123" - sprintf without decimal places
sprintf("%-15f", x)        # "123.456000" - Space on right side
sprintf("%+f", x)          # "+123.456000" - Print plus sign before number
Posted by: Guest on August-04-2021

Browse Popular Code Answers by Language