How to add a space in a variable in Rstudio

I want to add a space between the following variables in order to get this result:
2045 John Craine.
I would ask for your help since I can't find a way to do this in RStudio.

image

Enclose in backticks:

space_cadet <- `Air Head`

Better yet, use legal names in the data frame and adjust in the presentation table.

Hi @dcv8300, you need something like that ?

Status<- c('2045John Craine','2046Mary Craine')

gsub(Status, pattern = "(.{4})(.*)", replacement = "\\1 \\2")

# "2045 John Craine" "2046 Mary Craine"

1 Like

Thank you for your help :smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.