The Wayback Machine - https://web.archive.org/web/20230315104015/https://www.geeksforgeeks.org/print-a-formatted-string-in-r-programming-sprintf-function/
Skip to content
Related Articles
Open in App
Not now

Related Articles

Print a Formatted string in R Programming – sprintf() Function

Improve Article
Save Article
  • Last Updated : 03 Jun, 2020
Improve Article
Save Article

sprintf() function in R Language uses Format provided by the user to return the formatted string with the use of the values in the list.

Syntax: sprintf(format, values)

Parameter:
format: Format of printing the values
values: to be passed into format

Example 1:




# R program to illustrate 
# the use of sprintf() function
  
# Initializing values
x1 <- "Welcome"
x2 <- "GeeksforGeeks"
  
# Calling sprintf() function
sprintf("% s to % s", x1, x2)

Output:

[1] "Welcome to GeeksforGeeks"

Example 2:




# R program to illustrate 
# the use of sprintf() function
  
# Initializing values
x1 <- "GeeksforGeeks"
x2 <- 100
x3 <- "success"
  
# Calling sprintf() function
sprintf("% s gives %.0f percent % s", x1, x2, x3)

Output:

[1] "GeeksforGeeks gives 100 percent success"
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!