Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在集群上循环,作为向量返回_R_Loops_For Loop - Fatal编程技术网

R 在集群上循环,作为向量返回

R 在集群上循环,作为向量返回,r,loops,for-loop,R,Loops,For Loop,我有一个类似这样的循环 对于(2:10中的n){somc[n]你能提供更多的信息吗?somc是一个列表吗?这个等式的右边不会产生一个数字。我以前没有使用过这个,但我可能会这样做: input <- matrix(runif(100), ncol = 2) output_list <- list() num_clusters <- 2:10 for(i in num_clusters){ dist_matrix <- dist(input) my_cluste

我有一个类似这样的循环


对于(2:10中的n){somc[n]你能提供更多的信息吗?
somc
是一个列表吗?这个等式的右边不会产生一个数字。我以前没有使用过这个,但我可能会这样做:

input <- matrix(runif(100), ncol = 2)
output_list <- list()
num_clusters <- 2:10
for(i in num_clusters){
  dist_matrix    <- dist(input)
  my_cluster     <- hclust(dist_matrix)
  cut_my_cluster <- cutree(my_cluster, i)
  output_list[[paste(i)]] <- cut_my_cluster
}
output_list

input somc是一个我想回忆的向量,比如somc[2],它意味着2个集群等等。您的代码很有用,谢谢!