2

我有一个名为“输出”的原始向量列表。像这样的东西:

[1] 58 0a 00 00 00 03 00 04 00 03 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00 00 fe
[1] 58 0a 00 00 00 03 00 04 00 03 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 01 03 19 00 00 04 02 00 00 00 01 00 04 00 09 00 00 00 04 6d 65 74 61 00 00 02 13 00 00 00 03 00 00 00 10 00 00 00 01 00
[1] ...

它们具有不同的长度,并且来自“原始”类型。

我需要一个数据框,每个单元格中有一个向量:

ID 矢量图
1 58 0a 00 00 00 03 00 04 00 03 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00 00 费
2 58 0a 00 00 00 03 00 04 00 03 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 01 03 19 00 00 04 02 00 00 00 01 00 04 00 09 00 00 00 04 6d 65 74 61 00 00 02 13 00 00 00 03 00 00 00 10 00 00 00 01 00

我试过这个:

as.data.frame(output) 
#Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
  arguments imply differing number of rows: 27, 3132, 4141, 4267, 3701, 3943, 5200

df <- data.frame(matrix(unlist(output), nrow=length(output)))
#Warning message:
In matrix(unlist(output), nrow = length(output)) :
  data length [32954] is not a sub-multiple or multiple of the number of rows [14]

有没有办法解决我的问题?

4

2 回答 2

3

I创建data.frame时必须使用。

output <- list(raw(2), raw(3))
DF <- data.frame(ID=1:2, vectors = I(output))

str(DF)
#'data.frame':   2 obs. of  2 variables:
# $ ID     : int  1 2
# $ vectors:List of 2
#  ..$ : raw  00 00
#  ..$ : raw  00 00 00
#  ..- attr(*, "class")= chr "AsIs"

DF
#DF
#  ID    vectors
#1  1     00, 00
#2  2 00, 00, 00
于 2021-07-15T07:36:02.457 回答
1

这也可以用tibble

library(tibble)
output <- list(raw(2), raw(3))
tibble(ID = 1:2, vectors = output)
# A tibble: 2 x 2
     ID vectors  
  <int> <list>   
1     1 <raw [2]>
2     2 <raw [3]>
于 2021-07-15T17:08:11.233 回答