在使用dismo包中的kfold之后,我尝试选择这个函数从R列表中的不同数据集生成的组的子集。在单个数据集中,这很容易:
#With an individual dataset:
library(dismo)
data_car <- mtcars
group_presence <- kfold(x = data_car, k = 5) # kfold is in dismo package
# Separate observations into training and testing groups:
presence_train <- data_car[group_presence != 1, ]
但是,我似乎无法让它跨R中的列表中的多个数据集工作:
#Now, with listed datasets:
data_1 <- mtcars
data_2 <- iris
mylist <- list(data_1, data_2)
mylist_data <- lapply(mylist, function(q) {
data = q
return(data)
})
mylist_groups <- lapply(mylist, function(q) {
group_item = kfold(x = q,
k = 5)
q$group_obj = group_item
return(q)
})
presence_train <- mylist_groups[group_obj != 1, ]
#Result:
Error: object 'group_obj' not found
1条答案
按热度按时间kgsdhlau1#
我们可以使用
Map
其中