Name variable via a loop R
Name variable via a loop R I'm currently working on a function that will return distance between a point and p clusters. which_cluster<-function(coord){ cluster<-get_cluster(data) # return a matrix nbr_clusters=nrow(cluster) nbr_dim=ncol(cluster) liste<-c() for(i in 1:nbr_clusters){ dist_c_i=0 for (j in nbr_dim){ paste('vec_', i, sep = '') dim_j_c_i=cluster[i,j] dist_c_i<-dist_c_i+ (dim_j_c_i-coord[i])^2 } dist_c_i<-sqrt(dist_c_i) liste<-liste[,dist_c_i] } return(liste) } I want the "i" and "j" in the variable name to be recognize as the i and j of the for loop. Thank you for your help. Go easy on me, I'm a beginner ;) Hi! Could you provide a sample of your data? – Riverarodrigoa Jun 28 at 13:20 And an example of the output ...