Print a Formatted string in R Programming – sprintf() Function
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 valuesx1 <- "Welcome"x2 <- "GeeksforGeeks" # Calling sprintf() functionsprintf("% s to % s", x1, x2) |
Output:
[1] "Welcome to GeeksforGeeks"
Example 2:
# R program to illustrate # the use of sprintf() function # Initializing valuesx1 <- "GeeksforGeeks"x2 <- 100x3 <- "success" # Calling sprintf() functionsprintf("% s gives %.0f percent % s", x1, x2, x3) |
Output:
[1] "GeeksforGeeks gives 100 percent success"


Please Login to comment...