我有一个包含一个for循环,并创建一些地块这样的一些示例代码文本进度条(我的实际数据产生几千地块):R:在for循环
xy <- structure(list(NAME = structure(c(2L, 3L, 1L, 1L), .Label = c("CISCO","JOHN", "STEPH"), class = "factor"), ID = c(41L, 49L, 87L, 87L), X_START_YEAR = c(1965L, 1948L, 1959L, 2003L), Y_START_VALUE = c(940L,-1760L, 110L, 866L), X_END_YEAR = c(2005L, 2000L, 2000L, 2007L), Y_END_VALUE = c(940L, -1760L, 110L, 866L), LC = structure(c(1L,1L, 2L, 2L), .Label = c("CA", "US"), class = "factor")), .Names = c("NAME", "ID", "X_START_YEAR", "Y_START_VALUE", "X_END_YEAR", "Y_END_VALUE","LC"), class = "data.frame", row.names = c(NA, -4L))
ind <- split(xy,xy$ID) # split by ID for different plots
# Plots
for (i in ind){
xx = unlist(i[,grep('X_',colnames(i))])
yy = unlist(i[,grep('Y_',colnames(i))])
fname <- paste0(i[1, 'ID'],'.png')
png(fname, width=1679, height=1165, res=150)
par(mar=c(6,8,6,5))
plot(xx,yy,type='n',main=unique(i[,1]), xlab="Time [Years]", ylab="Value [mm]")
i <- i[,-1]
segments(i[,2],i[,3],i[,4],i[,5],lwd=2)
points(xx, yy, pch=21, bg='white', cex=0.8)
dev.off()
}
要查看进度for循环我有兴趣将进度条合并到我的代码中。正如我从R的文档中发现,有txtProgressBar
http://stat.ethz.ch/R-manual/R-patched/library/utils/html/txtProgressBar.html 从该页面的例子我明白,你必须编写for循环到一个函数后调用它,我正在努力与我的例子。
我该如何在for循环中实现进度条?
还检查了txtProgressBar的选项。它看起来好多了,如果你使用它们 – OganM
是的,我这样做,谢谢。唯一不起作用的是标题和标签选项?你碰巧知道一种解决方法,因为拥有一个标题会很酷。 – kurdtc
我通过使用'cat()'函数找到了一个解决方法。 – kurdtc