Home > Net >  join two vectors with the = in R
join two vectors with the = in R

Time:10-20

I want to join two vectors with the = symbol, so that the result will be: "a"="z","b"="y","c"="x"

a<-c("a","b","c")
b<-c("z","y","x")
c<-rbind(a,b)

CodePudding user response:

Assuming your desired output is as follows

c("a"="z","b"="y","c"="x")
#>   a   b   c 
#> "z" "y" "x"

this can be achieved using setNames with vectors a and b

a<-c("a","b","c")
b<-c("z","y","x")

setNames(b, a)
#>   a   b   c 
#> "z" "y" "x"

CodePudding user response:

a<-c("a","b","c")
b<-c("z","y","x")

c <- paste0(a, "=", b)
c

[1] "a=z" "b=y" "c=x"

CodePudding user response:

You may also use names<- i.e

names(b) <- a
b

# a   b   c 
#"z" "y" "x" 
  • Related