有人可以告诉我R中的以下语法有什么问题,我怎样才能使用" i"和" n"在文中,如情节的标题?
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] == ["
答案 0 :(得分:2)
使用paste
或paste0
命令:
plot( ...., main=paste0("cl[", i, "] and cluster[", n, "]"))