【发布时间】:2021-11-04 18:40:23
【问题描述】:
您好,我有这个数据框 (test),我想将列表 (AO) 中的每个元素除以另一列 (DP) 中的值:
df <- structure(list(DP = c("572", "594", "625", "594", "537", "513"
), AO2 = list(list(c(2, 2)), list(c(2, 2, 2)), list(c(4, 4)),
list(c(3, 2, 2, 2, 3)), list(c(2, 2)), list(c(2, 2)))), row.names = c(NA,
-6L), class = c("data.table",
"data.frame"))
df
我想在df 中创建一个新列,其中列表的每个值都除以同一行的df$DP 中的值。
我曾尝试使用 mapply,但没有成功。有什么想法吗?
test$AO2_DP <- mapply(FUN = `/`, list(as.numeric(unlist(test$AO2))), as.numeric(test$DP), SIMPLIFY = FALSE)
【问题讨论】:
-
请与
dput分享您的数据样本