r - 转换数据框中的原始向量列表
问题描述
我有一个名为“输出”的原始向量列表。像这样的东西:
[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]
有没有办法解决我的问题?
解决方案
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
推荐阅读
- nginx - 是否可以在 nginx 上拥有 2 个具有不同路由的相同 IP 的子域?
- python - 如何在 MDDialog 中添加 MDList(OneLineListItem)
- javascript - 将角度 5 更新为 6+ ngx-bootstrap 错误
- javascript - Tabulator.js - IE11 - “错误:未指定的错误......”
- ios - 无法在 iOS 14(模拟器和设备)上使用 VideoPlayer 播放 HEVC
- firebase - 我无法部署 Firebase 功能,因为我没有“服务帐户用户”角色
- python - youtube页面使用selenium向下滚动,python
- python - 将数据框列值编辑为特定格式
- javascript - 命名空间“google.maps”没有导出成员“MouseEvent”
- java - 未设置 X11 DISPLAY 变量。如何使用 java 从 linux 中的剪贴板获取数据?