我有一个名为myvec
的矢量(超过10000个项目)。我想按照相应的顺序展开带有扩展名(.GT
,.AD
,.DP
)的向量,并获取result
。
myvec<- c("Apple","Ball","Car")
结果:
Apple.GT, Apple.AD, Apple.DP, Ball.GT, Ball.AD, Ball.DP, Car.GT, Car.AD, Car.DP
答案 0 :(得分:4)
我们可以使用outer
c(outer(myvec, v1, FUN = paste0))
如果我们需要更改订单
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"
或者更快的选项是rep
paste
paste0(rep(myvec, length(v1)), rep(v1, each = length(myvec)))
v1 <-c(".GT",".AD",".DP")