繁体   English   中英

R - 矩阵的列数必须在 rbind 中匹配

[英]R - number of columns of matrices must match in rbind

我正在尝试 rbind 矩阵列表以创建数据帧但出现错误。

txt<-grep("^#",
       readLines("offline.txt"),
       invert = TRUE,
       value = TRUE)


processLine = function(x)

{

 tokens = strsplit(x, "[;=,]")[[1]]
 tmp = matrix(tokens[ - (1:10) ], ncol = length(tokens[-(1:10)]), byrow = TRUE)
 cbind(matrix(tokens[c(2, 4, 6:8, 10)], nrow = nrow(tmp), ncol = 6, byrow= TRUE), tmp)

 }

 tmp = lapply(txt, processLine)

 sapply(tmp, nrow)

 offline = as.data.frame(do.call("rbind", tmp))


 Error: Error in rbind(c("1139643118358", "00:02:2D:21:0F:33", "0.0", "0.0", "0.0", : number of 
 columns of matrices must match (see arg 2)

数据数据集的链接

试试 data.table 库。

library(data.table)
df<-rbindlist(tmp, fill = T)

确保列表中的项目实际上是 data.frame、data.table 或 list。 不是矩阵或数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM