我现在正在处理一个大型数据集,某些功能可能需要几个小时才能处理。我想知道如何通过进度条或数字(1,2,3,...,100)显示代码的进度。这是一个例子。谢谢。
require(Kendall)
mydata=matrix(rnorm(6000*300),ncol = 300)
result=as.data.frame(matrix(nrow = 6000,ncol = 2))
for (i in 1:6000) {
abc=MannKendall(mydata[i,])
result[i,1]=abc$tau
result[i,2]=abc$sl
}
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我发现链接https://ryouready.wordpress.com/2009/03/16/r-monitor-function-progress-with-a-progress-bar/非常有用。但是,我不知道如何将链接中的代码与自己的函数结合在一起。有人有主意吗?谢谢。这是上面链接的代码。
total <- 20
# create progress bar
pb <- txtProgressBar(min = 0, max = total, style = 3)
for(i in 1:total){
Sys.sleep(0.1)
# update progress bar
setTxtProgressBar(pb, i)
}
close(pb)
Run Code Online (Sandbox Code Playgroud)
这应该有效:
mydata=matrix(rnorm(6000*300),ncol = 300)
result=as.data.frame(matrix(nrow = 6000,ncol = 2))
progression<-winProgressBar(title = "Progress bar", min = 0,max = 6000 , width = 300)
for (i in 1:6000) {
abc=MannKendall(mydata[i,])
result[i,1]=abc$tau
result[i,2]=abc$sl
setWinProgressBar(progression, i, title=paste(round(progress/6000)*100,"% done"))
}
Run Code Online (Sandbox Code Playgroud)