求R语言解读,每一行求解答,真的不太看得懂

panel.cor <- function(x, y, digits = 2, prefix = "", cex.cor, ...)
{
tmp <- data.frame(x,y)
tmp$flgx <- 0
tmp$flgx[is.na(tmp$x)] <- 1
tmp$flgy <- 0
tmp$flgy[is.na(tmp$y)] <- 1
tmp <- tmp[tmp$flgx==0&tmp$flgy==0,]
x <- tmp$x
y <- tmp$y
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- cor(x, y)
txt <- format(c(r, 0.123456789), digits = digits)[1]
txt <- paste0(prefix, txt)
if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt)
# text(0.5, 0.5, txt, cex = cex.cor * r)
text(0.5, 0.5, txt, cex = 1)
}
panel.hist <- function(x, ...)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(usr[1:2], 0, 1.5) )
h <- hist(x, plot = FALSE)
breaks <- h$breaks; nB <- length(breaks)
y <- h$counts; y <- y/max(y)
rect(breaks[-nB], 0, breaks[-1], y, col = "lightblue", ...)
}

第1个回答  2023-05-01
首先有个概念,循环中的变量是i,每次循环之后都会更新i的值,直到循环结束。循环中i的取值范围在1:5。
循环中,每次循环都打印出i的结果。
循环结束后,i不再更新,打印i输出的就是i最后一次的取值,并且一直都是这个值,除非你再次给i赋值。

第二个问题,我不知到是不是这个意思,你需要保存每一步循环中得到的结果,最后在循环结束之后全部把它们输出出来。

我就按我理解的这个意思写一下。

t<-array()
for(i in 1:5) t[i]<-i
a<-list(t);a

希望对你有帮助。
第2个回答  2023-03-25
你复制的时候出现的错误,末尾多了或者少了一行等的错误,建议重新复制到剪切板,然后看看。最好读本地文件,读复制的文件,每次这样做很麻烦,还容易出错。
相似回答