nested for loop in R, using variable in title , -


can tell me what's wrong following syntax in r, , how can use variable "i" , "n" in text, title of plot?

 j <- c(5,10,15,20)  (n in j){      (i in 1:n) {            cl[i] <- subset(data, data$cluster[n] == [i])        ...         plot( ...., main="cl[i] , cluster[n]")  }}  error: unexpected '[' in: "for (i in 1:n) { cl[i] <- subset(data, data$cluster[n] == [" 

use paste or paste0 command:

plot( ...., main=paste0("cl[", i, "] , cluster[", n, "]")) 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -