将函数应用于越来越大的数据框子集

Applying a function to increasingly larger subsets of a data frame

我想将统计函数应用于越来越大的数据框子集,从第 1 行开始,每次增加 10 行。所以第一个子集是第 1-10 行,第二个子集是第 1-20 行,最后一个子集是第 1-n 行。这可以在没有 for 循环的情况下完成吗?如果是,怎么做?

这是一种解决方案:

# some sample data
df <- data.frame(x = sample(1:105, 105))

#getting the endpoints of the sequences you wanted
row_seq <- c(seq(0,nrow(df), 10), nrow(df))

#getting the datasubsets filtering df from 1 to each endpoint  
data.subsets <- lapply(row_seq, function(x) df[1:x, ])

# applying the mean function to each data-set
#  just replace the function mean by whatever function you want to use
lapply(data.subsets, mean)