gpt4 book ai didi

r - 如何测试数据框内容?

转载 作者:行者123 更新时间:2023-12-03 09:42:26 27 4
gpt4 key购买 nike

我有一个返回数据帧的例程。我想检查它的值是否合理。使用 testthat我有 expect_equal ,但我不确定它是否适用于 data.frames。我试图这样做,但它不起作用

testthat::expect_equal(result$ORs[1,1:3], c(1.114308, 0.5406599, 2.296604), tolerance=1.0e-6)

这是我收到的消息
─────────────────────────────────────────────────
test-xxx.R:19: failure: basic functionality
result$ORs[1, 1:3] not equal to c(1.114308, 0.5406599, 2.296604).
Modes: list, numeric
names for target but not for current
Attributes: < Modes: list, NULL >
Attributes: < Lengths: 2, 0 >
Attributes: < names for target but not for current >
Attributes: < current is not list-like >
─────────────────────────────────────────────────

══ Results ══════════════════════════════════════
Duration: 0.1 s

最佳答案

如果您只是测试特定列的值(例如 df[1,1] ),那么您可以 unnameunlist值(value):

expect_equal(unname(unlist(df[1,1])), "Value")

关于r - 如何测试数据框内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58026951/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com