gpt4 book ai didi

r - 在 R 中运行 apply 函数时有没有办法打印迭代次数

转载 作者:行者123 更新时间:2023-12-02 01:33:34 24 4
gpt4 key购买 nike

我在一个大数据集上运行了一个 apply-family 函数,所以我想知道是否有办法知道到目前为止工作进展如何,到目前为止查看了多少元素,或者类似的东西?

最佳答案

您可以考虑创建一个全局计数器,并指定何时打印进度,例如,每当处理完 10% 的数据时,您可以打印通知;

counter <- 0
data <- rnorm(100)
results <- sapply(data, function(x) {
counter <<- counter + 1;
if(counter %in% seq(0, length(y), 10))
print(paste(counter, "% has been processed"))})

[1] "10 % has been processed"
[1] "20 % has been processed"
[1] "30 % has been processed"
[1] "40 % has been processed"
[1] "50 % has been processed"
[1] "60 % has been processed"
[1] "70 % has been processed"
[1] "80 % has been processed"
[1] "90 % has been processed"
[1] "100 % has been processed"

关于r - 在 R 中运行 apply 函数时有没有办法打印迭代次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37621882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com