r - How to separate my output by comma? -
km<-kmeans(iris,3) scorekm<- function(km, x,...) { args<-list(x,...) result=null for(i in seq(from=1,to=nargs()-1,by=4)) { data<-matrix(c(args[[i]],args[[i+1]],args[[i+2]],args[[i+3]]),nrow=1) k <- nrow(km$centers) d <- as.matrix(dist(rbind(km$centers, data)))[-(1:k),1:k] d <- matrix(d,nrow=1) category<- apply(d,1,which.min) result<-cbind(category,result) } return(result) } now, output this: > scorekm(km,5.9,3.0,5.1,1.8,5.1,3.8,1.6,0.2) category category category >[1,] 1 2 how can change this: >[1,] 1,2 output separated comma. as roland asked, why relevant, don't know how wish use output. should return "result" character string comma. change line result<-cbind(category, result) result<-paste(category, ",", result, sep="") . hope helps. greetins, ben