I have a vector called myvec ( with more than 10000 items). I want to expand the vector with the extensions (.GT, .AD, .DP) in the corresponding order and get the result.
myvec<- c("Apple","Ball","Car")
result:
Apple.GT, Apple.AD, Apple.DP, Ball.GT, Ball.AD, Ball.DP, Car.GT, Car.AD, Car.DP
We can use outer
c(outer(myvec, v1, FUN = paste0))
If we need to change the order
c(t(outer(myvec, v1, FUN = paste0)))
#[1] "Apple.GT" "Apple.AD" "Apple.DP" "Ball.GT" "Ball.AD" "Ball.DP"
#[7] "Car.GT" "Car.AD" "Car.DP"
Or a faster option would be rep with paste
paste0(rep(myvec, length(v1)), rep(v1, each = length(myvec)))
v1 <-c(".GT",".AD",".DP")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With