Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function Modifying a Character String

I need a function that will take input as a character string (BLANK) and print out the following:

"Hello BLANK World"

i.e., world("seven") prints out "Hello seven World"

I'm very confused on how to work with character strings in R.

like image 938
user3084629 Avatar asked May 10 '26 03:05

user3084629


2 Answers

You want the function paste

world <- function(x) paste("Hello", x, "World")
like image 168
Matthew Lundberg Avatar answered May 12 '26 18:05

Matthew Lundberg


Or...

 x <- "seven"
 sprintf("Hello %s World", x)

In other words no need for a world function as that's what sprintf does.

like image 45
Tyler Rinker Avatar answered May 12 '26 18:05

Tyler Rinker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!