Paste together two character vectors of different lengths

后端 未结 3 1848
日久生厌
日久生厌 2020-12-31 21:01

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\",         


        
相关标签:
3条回答
  • 2020-12-31 21:35

    outer

    outer(groups, labels, FUN=paste)

    0 讨论(0)
  • 2020-12-31 21:49

    Probably outer helps your work. Try this:

    > c(t(outer(groups, label, paste)))
    [1] "Group A Time" "Group A Min"  "Group A Mean" "Group A Max"  "Group B Time" "Group B Min" 
    [7] "Group B Mean" "Group B Max" 
    
    0 讨论(0)
  • 2020-12-31 21:52

    Since it's two element array, I would do

     c(paste(groups[1],label),paste(groups[2],label))
    
    0 讨论(0)
提交回复
热议问题