Printing results

Results can be printed in R using print, cat, and other commands:

# print is often used as a means to document code output as 
(function(x){x=10;print ("x is now 10")})() 

print also supports other flags such as digits (number of digits to print), justify (left and right), quote (whether strings should be quoted), for example:

print (1.1234567,digits=3) 

Formatting strings can be done using the format command in R. It is one of the most versatile functions that allows users to present data in a more readable manner. For instance, to add a comma (,) separator to numbers, we can use the big.mark argument in the format as follows:

format(14324234,big.mark=",") 

Other options as specified in the R help page include the following: ...

Get Hands-On Data Science with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.