我想在循环中运行一个函数,其中输入数据来自具有连续数字的列表,如下所示:
output <-create_list(input) %% function that creates the list
输出具有M1,N1,M2,N2,M3,N3,M4和N4
for (i in 1:4) {
m <- output$M[i] %% This is wrong but is a good way to show my aim
n <- output$N[i]
output2<- fiting(m,n) %% target function
}
答案 0 :(得分:0)
尝试:
# You want to keep the fits you generate, a list can hold everything
fits <- list()
# This generates a sequence that increments be two:
# i.e: 1, 3, 5, 7 etc, it won't generate any value greater
# than the maximum value (defined by length(output))
for(i in seq(1, length(output), by = 2))
# Then just run the fitting function on each two values
fits <- c(fits, fitting(output[[i]], output[[i + 1]]))
# Fits then contains a list of outputs