如何粘贴功能在R中工作? [英] how paste function working in R?

查看:317
本文介绍了如何粘贴功能在R中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码



这里的粘贴函数只适用于两个组合。在同一个循环中需要两个以上组合的相同代码。

  i< -2 

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

现在我得到两个组合,如

  V1V2,V1V3,V1V4,... 

现在我想要

  v1v2v3,v1v2v4,... 
/ code code code code code code $ c

$ b 解决方案

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



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



粘贴使用 paste0



@henrik和@chargaff


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.

解决方案

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

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

insted of paste use paste0

@henrik and @chargaff

这篇关于如何粘贴功能在R中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆