粘贴矢量的字符串索引

时间:2019-06-02 01:04:13

标签: r paste

这是我的示例代码尝试

  paste(1:2,"x",0:1)

这是输出

[1] "1x0" "2x1"

但这是我期望的输出:

[1] "1x0" "1x1" "2x0" "2x1"

1 个答案:

答案 0 :(得分:1)

使用expand.grid

apply(expand.grid(1:2,"x",0:1),1,paste,collapse="")
[1] "1x0" "2x0" "1x1" "2x1"