替换R中列表列表列中的值
我有一个列名称列表,并试图替换列的值。包含所有名为替换R中列表列表列中的值,r,list,R,List,我有一个列名称列表,并试图替换列的值。包含所有名为all_list的列表的我的列表如下所示: [[1]] preds ground_truth 19221 0.0566264 1 6587 0.0567813 0 3981 0.0569643 0 16956 0.0570841 1 2344 0.0570878 1 2855 0.0571354
all_list
的列表的我的列表如下所示:
[[1]]
preds ground_truth
19221 0.0566264 1
6587 0.0567813 0
3981 0.0569643 0
16956 0.0570841 1
2344 0.0570878 1
2855 0.0571354 1
[[2]]
preds ground_truth
17326 0.7525393 0
26342 0.7586699 1
15996 0.7703387 1
14033 0.7738193 0
3403 0.7838794 1
20626 0.8009424 1
16675 0.8294433 1
[[3]]
[1] preds ground_truth
<0 rows> (or 0-length row.names)
但是,我得到以下错误:
Error in matrix(unlist(value, recursive = FALSE, use.names = FALSE), nrow = nr, :
'data' must be of a vector type, was 'NULL'
有人知道如何解决这个问题吗?谢谢您可以
对所有列表中的preds
列进行排序
:
all_lists <- lapply(all_lists, function(x) {
x$preds = round(x$preds)
#If your data can go above 1
#x$preds = as.integer(x$preds > 0.5)
x
})
所有列表(0.5)
x
})
对于自定义阈值,您可以使用映射:
nlist <- Map(function(x) {x$preds <- ifelse(x$preds > 0.5, 1, 0); x}, nlist)
nlist太好了,谢谢。作为一个额外的问题,你知道如何获得这些群体的auc吗?我试过auc(列出[ground\u truth],列出[preds.hold])
但它说ground\u truth
没有发现我没有你的数据,但可能lappy(所有列表,函数(x)auc(x$ground\u truth,x$preds.hold))
?
nlist <- Map(function(x) {x$preds <- ifelse(x$preds > 0.5, 1, 0); x}, nlist)
df <- data.frame(preds = runif(10), ground=sample(0:1, size = 10, replace = T))
nlist = list(df, df)