Skip to content
Related Articles

Related Articles

Improve Article

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

  • Last Updated : 03 Jun, 2020

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
Recommended Articles
Page :