我试图用列表对象创建一个数据框,使数据框的列名成为列表对象的变量名,并将列表的值绑定到每一列。示例:给定列表
badStateInputs <- list("nd", "NORTH DAKOTA", "N. Dakota", "N DAKOTA", "VT", "V t", "Nevada")
emptyOrNonString <- list(NULL, "", " ", 3, numeric(), character(), 1.34)
获取看起来像的数据框的最佳方法是什么
"badStateInputs" "emptyOrNonString"
1 "nd" NULL
2 "NORTH" ""
3 etc. etc.
我尝试过:
test.data <- data.frame(badStateInputs, emptyOrNonString, stringsAsFactors = FALSE)
它扔了
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
arguments imply differing number of rows: 0, 1
对不起,我是R的新手,因此必须学习各种对象才是学习的起点。我希望能够遍历每一行以进行测试,例如:
for(input in 1:nrow(test.data[input, "badStateInputs"]))
{
expected <- input
actual <- foo(...)
expect_equal(actual, input)
}