将两个不同长度的字符向量粘贴在一起
我在 R 中有两个不同的字符向量,我想将它们组合起来用于列名称:
groups <- c("Group A", "Group B")
label <- c("Time","Min","Mean","Max")
当我尝试使用粘贴时,我得到结果:
> paste(groups,label)
[1] "Group A Time" "Group B Min" "Group A Mean" "Group B Max"
是否有一个简单的函数或设置可以将它们粘贴在一起以获得以下输出?
[1] "Group A Time" "Group A Min" "Group A Mean" "Group A Max" "Group B Time"
[6] "Group B Min" "Group B Mean" "Group B Max"
I have two different character vectors in R, that I want to combine to use for column names:
groups <- c("Group A", "Group B")
label <- c("Time","Min","Mean","Max")
When I try using paste I get the result:
> paste(groups,label)
[1] "Group A Time" "Group B Min" "Group A Mean" "Group B Max"
Is there a simple function or setting that can paste these together to get the following output?
[1] "Group A Time" "Group A Min" "Group A Mean" "Group A Max" "Group B Time"
[6] "Group B Min" "Group B Mean" "Group B Max"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许
outer
对您的工作有帮助。试试这个:Probably
outer
helps your work. Try this:outer
外部(组、标签、FUN=粘贴)
outer
outer(groups, labels, FUN=paste)
由于它是两个元素数组,我会这样做
Since it's two element array, I would do