如何将对象转换为数据框类对象?
我正在尝试在 R 中创建桑基图,但我不断收到错误消息,其中一个参数需要是数据帧类对象。参见下文:
library(d3Network)
d3Sankey(Links = df2[ ,('value')], Nodes = df3[ , c('name')], Source = "source",
Target = "target")
Error in d3Sankey(Links = df2[, ("value")], Nodes = df3[, c("name")], :
Links must be a data frame class object.
df2 <- as.data.frame(df2)
d3Sankey(Links = df2[ ,('value')], Nodes = df3[ , c('name')], Source = "source",
Target = "target")
Error in d3Sankey(Links = df2[, ("value")], Nodes = df3[, c("name")], :
Links must be a data frame class object.
typeof(df2)
[1] "list"
有了这些信息,有谁知道如何将 df2 转换为数据框类对象?
I'm trying to create a Sankey Plot in R, but I keep getting an error that one of the parameters needs to be a Data Frame Class Object. See below:
library(d3Network)
d3Sankey(Links = df2[ ,('value')], Nodes = df3[ , c('name')], Source = "source",
Target = "target")
Error in d3Sankey(Links = df2[, ("value")], Nodes = df3[, c("name")], :
Links must be a data frame class object.
df2 <- as.data.frame(df2)
d3Sankey(Links = df2[ ,('value')], Nodes = df3[ , c('name')], Source = "source",
Target = "target")
Error in d3Sankey(Links = df2[, ("value")], Nodes = df3[, c("name")], :
Links must be a data frame class object.
typeof(df2)
[1] "list"
With this information, does anyone know how to convert df2 to a data frame class object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Links
、Nodes
应该是 data.frames -Links
data.frame 应该有三列source
、目标
和值
,具有单列名称
的节点
。在OP的代码中,两者都作为向量
提供,因为在data.frame
中,如果我们使用带有单个列名的,
,它删除尺寸(drop = TRUE
- 默认情况下)。为了保存输出,请指定file
The
Links
,Nodes
should be data.frames -Links
data.frame should have three columnssource
,target
andvalue
,Nodes
with a single columnname
. In the OP's code, both are provided asvector
s because indata.frame
, if we use a,
with a single column name, it drops the dimensions (drop = TRUE
- by default). In order to save the output, specifyfile