how paste function working in R? [duplicate]

不打扰是莪最后的温柔 提交于 2019-12-13 10:37:53

问题


this is my code

here the paste function works for only two combination.i need the same code in a loop for more than two combinations at the same time.

i<-2

while (i<=10)
 {
 results<-data.frame()
 results<- t(apply(data,1,function(x) combn(x,i,prod)))
 comb <- combn(colnames(data),i)
 colnames(results) <- apply(comb,i,function(x) paste(x[1],x[2]))
 i<-i+1
 }

now i get the two combination like

V1V2, V1V3,V1V4,....

now i want

 v1v2v3, v1v2v4, ... 

in paste function.


回答1:


comb <- combn(colnames(data),v)

colnames(results) <- apply(comb,2,function(rows) paste0(rows, collapse = ""))

insted of paste use paste0

@henrik and @chargaff



来源:https://stackoverflow.com/questions/20291599/how-paste-function-working-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!