EpiMan
EpiMan

Reputation: 839

nested for loop in R, using variable in title ,

Can somebody tell me what's wrong with the following syntax in R, and how can I use variable like "i" and "n" in the text, like title of a plot?

 j <- c(5,10,15,20)

for (n in j){

    for (i in 1:n) {

          cl[i] <- subset(data, data$cluster[n] == [i])

      ...

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

}}

Error: unexpected '[' in:
"for (i in 1:n) {
cl[i] <- subset(data, data$cluster[n] == ["

Upvotes: 1

Views: 184

Answers (1)

ialm
ialm

Reputation: 8717

Use the paste or paste0 command:

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

Upvotes: 2

Related Questions