【发布时间】:2021-07-21 15:06:35
【问题描述】:
我正在尝试使用dlply 函数将data.frame 对象转换为matrix 格式,但结果对象显然不是matrix 格式。
谁能指出这里发生了什么?
library(plyr)
#load the data
export <- readRDS(url("https://www.dropbox.com/s/7nn4kcdbsiteplj/export.rds?dl=1"))
export_mat <- dlply(export,.(reporter_iso), fun = as.matrix)
str(export_mat)
List of 161
$ afg:'data.frame': 161 obs. of 6 variables:
..$ reporter_iso: chr [1:161] "afg" "afg" "afg" "afg" ...
..$ partner_iso : chr [1:161] "afg" "ago" "alb" "are" ...
..$ cong_pct : num [1:161] 0 0 0 0.0915 0 ...
..$ cag_pct : num [1:161] 0 0 0 0.0297 0 ...
..$ ig_pct : num [1:161] 0 0 0 0.049 0 ...
..$ rm_pct : num [1:161] 0 0 0 0.83 0 ...
..- attr(*, "vars")= chr "reporter_iso"
$ ago:'data.frame': 161 obs. of 6 variables:
..$ reporter_iso: chr [1:161] "ago" "ago" "ago" "ago" ...
..$ partner_iso : chr [1:161] "afg" "ago" "alb" "are" ...
..$ cong_pct : num [1:161] 0 0 0 0.203 0 ...
..$ cag_pct : num [1:161] 0 0 0 0.698 0 ...
..$ ig_pct : num [1:161] 0 0 0 0.0148 0 ...
..$ rm_pct : num [1:161] 0 0 0 0.0842 1 ...
..- attr(*, "vars")= chr "reporter_iso"
【问题讨论】: