代码:
plot.new()
plot.window(xlim = c(0, 5), ylim = c(0, 5), asp = 1)
for (r in 0:5){
segments(x0 = 0, y0 = r, x1 = 5, y1 = r)
}
for (c in 0:5){
segments(x0 = c, y0 = 0, x1 = c, y1 = 5)
}
for (i in 1:25){
if (i%%5 == 0){
text(i - 0.5, (i%/%5-1) + 0.5, labels = as.character(i))
}else{
text(i%%5 - 0.5, i%/%5 + 0.5, labels = as.character(i))
}
}
if语句应该能够帮助我将数字放在正确的列中,但实际上并不起作用
2条答案
按热度按时间5vf7fwbs1#
问题是,当你点击5的倍数时,你把
x
坐标设置为i - 0.5
,但是你总是希望x
坐标为4.5。mpbci0fu2#
以下是一种不同的方法,没有任何循环或分割: