简体   繁体   English

粘贴矢量的字符串索引

[英]Paste String Indexing For Vector

This is my example code attempt 这是我的示例代码尝试

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

This is the output 这是输出

[1] "1x0" "2x1"

But this is my Desired output: 但这是我期望的输出:

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

Using expand.grid 使用expand.grid

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM