【发布时间】:2021-10-06 17:20:45
【问题描述】:
我一定是被一杯茶淹死了,但与此同时,我已经把头撞在墙上好几个小时了。 请看下面的reprex,其中我生成了一个igraph 图形对象g,并将源自某些顶点的边收集到一个名为dd 的对象中。 我的目标是将 dd 转换为数据帧或 tibble,但最明显的方法(as_data_frame 和 as_tibble)完全失败。 谁能帮帮我?
非常感谢
library(tidyverse)
library(igraph)
#>
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:dplyr':
#>
#> as_data_frame, groups, union
#> The following objects are masked from 'package:purrr':
#>
#> compose, simplify
#> The following object is masked from 'package:tidyr':
#>
#> crossing
#> The following object is masked from 'package:tibble':
#>
#> as_data_frame
#> The following objects are masked from 'package:stats':
#>
#> decompose, spectrum
#> The following object is masked from 'package:base':
#>
#> union
g <- make_ring(10)
dd <- E(g)[from(1:4)]
## this does not work
dd%>%as_tibble
#> Error in as.data.frame.default(value, stringsAsFactors = FALSE): cannot coerce class '"igraph.es"' to a data.frame
## neither this
dd%>%as_data_frame
#> Error in as_data_frame(.): Not a graph object
## so what to do?
由reprex package (v2.0.0) 于 2021 年 7 月 31 日创建
【问题讨论】:
-
您提供的代码没有描述基本问题和目标。
-
我完全不同意。我想将收集到 dd 的一堆边转换为数据框或小标题,以便进一步操作。请阅读整篇文章。
-
发布失败的代码通常对理解目标没有用处。您现在应该使用 SO 的 edit 设施来接受您评论中的材料并改进问题。