簡體   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