与R中的循环绑定 [英] cbind with loop in R

查看:54
本文介绍了与R中的循环绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是R的新手,所以遇到了问题所以我的问题是:我有倍数表,例如:10,也与与此表有关的kmeans结果不同(10).所以我想使用cbind以便将每个群集添加到其表中:

I'm new with R and I've an issue So my issue is : I've multiples tables ex: 10 , also different list from kmeans results related to this tables (10). So I want use cbind in order to add each cluster to its table :

例如:

NEW_table1<- cbind(table1,kmeans_table1$cluster)
NEW_table2<- cbind(table2,kmeans_table2$cluster)

...

我尝试使用此代码,但出现错误

I've tryd with this code but a get an error

for (i in 1:10)
{ assign(paste0("NEW_table", i)<-cbind(as.name(paste0("filter_table",i)),Class=(i$cluster) )) 
}

> Error in i$cluster : $ operator is invalid for atomic vectors

推荐答案

谢谢大家,我通过以下代码修复了问题:

thank you all, I'v fixed by the following code:

# VAR its a list of distinct values from column in large table
VAR<- unique(table$column)

for(i in VAR){
  assign( 

    paste0("New_table", i),cbind(get(paste0("filter_table",i)),Class=get(i)$cluster)
    )
}

这篇关于与R中的循环绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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