Barnaby
Barnaby

Reputation: 1480

Placing a number between letters of a character expression

I would like to place an object result between a character expression

A<-2+2 # object 
zlog #carácter expression I would like to insert the result of an object 

So it becomes

z4log

Upvotes: 1

Views: 62

Answers (1)

AndriusZ
AndriusZ

Reputation: 822

I would suggest:

A <- 2+2 # object 
B <- "zlog" #carácter expression I would like to insert the result of an object 
sub('(?<=.{1})', A, B, perl = TRUE)

Correction is made according to @Pascal comment.
T is replaced with TRUE

Upvotes: 2

Related Questions