0
"for"ループを作成するのに非常に簡単な質問でしょう。ここで私は(AAは行列である)ループを使用して行うことをしようとしていますものです:異なる変数を使ってforループを作成する
lines(x = c(AAx[1:2,1]), y = c(AAx[1:2,2]))
lines(x = c(AAx[3:4,1]), y = c(AAx[3:4,2]))
lines(x = c(AAx[5:6,1]), y = c(AAx[5:6,2]))
lines(x = c(AAx[7:8,1]), y = c(AAx[7:8,2]))
lines(x = c(AAx[9:10,1]), y = c(AAx[9:10,2]))
lines(x = c(AAx[11:12,1]), y = c(AAx[11:12,2]))
lines(x = c(AAx[13:14,1]), y = c(AAx[13:14,2]))
lines(x = c(AAx[15:16,1]), y = c(AAx[15:16,2]))
lines(x = c(AAx[17:18,1]), y = c(AAx[17:18,2]))
lines(x = c(AAx[19:20,1]), y = c(AAx[19:20,2]))
lines(x = c(AAx[21:22,1]), y = c(AAx[21:22,2]))
lines(x = c(AAx[23:24,1]), y = c(AAx[23:24,2]))
私が試した:
i <- c(1,3,5,7,9,11,13,15,17,19,21,23)
j <- c(2,4,6,8,10,12,14,16,18,20,22,24)
for (i in i){
for (j in j){
lines(x = c(AAx[i:j,1]), y = c(AAx[i:j,2]))
}
}
しかし、成功しませんでした。私は簡単な方法があると確信していますが、今のところそれを理解することはできません。どんな助けもありがたい。
は、私は2番目が、同様の問題があります。
text(AAx[1,1],AAx[1,2], names[1], pos = 3)
text(AAx[3,1],AAx[3,2], names[2], pos = 3)
text(AAx[5,1],AAx[5,2], names[3], pos = 3)
text(AAx[7,1],AAx[7,2], names[4], pos = 3)
text(AAx[9,1],AAx[9,2], names[5], pos = 3)
text(AAx[11,1],AAx[11,2], names[6], pos = 3)
text(AAx[13,1],AAx[13,2], names[7], pos = 3)
text(AAx[15,1],AAx[15,2], names[8], pos = 3)
text(AAx[17,1],AAx[17,2], names[9], pos = 3)
text(AAx[19,1],AAx[19,2], names[10], pos = 3)
text(AAx[21,1],AAx[21,2], names[11], pos = 3)
text(AAx[23,1],AAx[23,2], names[12], pos = 3)
names <- c(“AA”,”BB”,”CC”,”DD”,”EE”,”FF”,”GG”,”HH”,”EE”,”JJ”,”KK”,”LL”)
j <- c(1,3,5,7,9,11,13,15,17,19,21,23)
を私が試した:
for (i in j){
for (k in 1:length(names)){
text(AAx[i,1],AAx[i,2], names[k], pos = 3)
}
}
私は最初の問題から有用な答えを受けたが、私はまだ二番目にこだわっています。どんな助けにも感謝!
'のAAX [I:(I + 1)、...]'または 'AAX [C(I、I + 1)、...]' – HubertL
不要にy = AAx [i:(i + 1)、2](x = AAx [i:(i + 1)、1] – lmo
lines()に何をしたいかは少し不明です。これはxとyのパラメータで呼び出すメソッドですか?xとyはリストですか? –