r数据处理
R 报错:All columns in a tibble must be vectors
tibble() / tribble() 里传入了矩阵、列表或函数作为列。
报错原文
Error: All columns in a tibble must be vectors.为什么会报这个错
tibble() / tribble() 里传入了矩阵、列表或函数作为列。
怎么解决
列必须是向量;矩阵先 as.data.frame() 或按列拆开;列表列要用 list() 显式包裹。
代码示例
# 错误
tibble(m = matrix(1:4, 2))
# 正确
tibble(a = c(1, 2), b = c(3, 4))
# 列表列
tibble(x = list(1:3, 4:6))同工具的其他报错
- R 报错:Join columns must be present in data(连接键不存在)
- R 报错:Column `x` must be length 1 or n(mutate 里长度不匹配)
- R 报错:Problem with `mutate()` input `x`(管道内层报错)
- R 报错:Can't transform a data frame with duplicate names
- R 报错:`by` required, because the data sources have no common variables
- R 报错:must be a vector, not a data frame(传了数据框当参数)
报错解决了,但方法还没搞懂?
报错只是表象。因果推断、面板数据、稳健性检验这些方法背后的逻辑,知识库里按「原理 × 直觉 × 代码」讲清楚了。
进入知识库 →