,可以使用以下代码实现:
# 嵌套列表
nested_list <- list(
list(a = 1, b = 2, c = 3),
list(d = 4, e = 5, f = 6),
list(g = 7, h = 8, i = 9)
)
# 采样函数
sample_from_nested_list <- function(nested_list) {
sampled_list <- list()
for (i in 1:length(nested_list)) {
sampled_list[[i]] <- sample(nested_list[[i]], 1)
}
return(sampled_list)
}
# 采样结果
sampled_list <- sample_from_nested_list(nested_list)
上述代码中,我们首先定义了一个嵌套列表nested_list
,其中包含了三个子列表。然后,我们定义了一个名为sample_from_nested_list
的函数,该函数接受一个嵌套列表作为参数,并从每个子列表中采样一个元素。最后,我们调用sample_from_nested_list
函数,并将采样结果存储在sampled_list
中。
这样,我们就从嵌套列表中的每个列表中采样了一个元素,创建了样本组。
领取专属 10元无门槛券
手把手带您无忧上云