如何在R中将数据帧上传到ndtv? [英] How upload a dataframe to ndtv in R?

查看:88
本文介绍了如何在R中将数据帧上传到ndtv?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是使用R中的三个程序包进行动态可视化: ndtv network networkDynamic 包。

My goal is to make a dynamic visualization using three packages in R: ndtv, network, and networkDynamic packages.

我创建了数据集,根据此示例数据集在网络动态时间可视化的车间(第7页)。

I have created a dataset with the information ordered according to this example dataset in a workshop for Network Dynamic Temporal Visualizations (on page 7.)

根据网络动态第49页手册,一种上传数据集并将其转换为networkDynamic对象的方法如下:

According to page 49 of the network dynamic manual, one way to upload a dataset and convert it into a networkDynamic object is as follows:

rawEdges<-read.table(paste(path.package("networkDynamic"),"/enron_timebased3.tsv", sep=''),header=TRUE)

但是,当我尝试运行
animation.render(rawEdges)

R抛出错误消息:


第一个参数必须是网络对象。

first argument must be a network object.

要解决此问题,我创建了网络对象:
net< -network(rawEdges)

To fix this, I create a network object: net<-network(rawEdges)

并尝试:

animation.render(net,rawEdges)

新错误消息:


'$<-。data.frame'(' tmp ', initial。 coords,值= c(0,0,0,:替换具有34行,数据具有26)

Error in '$<-.data.frame'('tmp', "initial.coords", value = c(0, 0, 0, : replacement has 34 rows, data has 26)

有人知道如何要解决此问题?

Does anyone know how to fix this?

推荐答案

您的示例有几个问题:


  • 您将需要创建 networkDynamic 对象,而不是网络
    对象

  • 您将必须对
    表进行一些时间格式转换以正确解析,并创建数字ID

  • 命令为 render。 animation()不是 animation.render()

  • you will need to create a networkDynamic object, not a network object
  • you will have to do some time format conversion for the table to parse correctly, as well as create numeric ids
  • the command is render.animation() not animation.render()

首先,让我们设置一些可以加载的示例数据。只需要示例数据的前4列:

First, lets set up some example data we can load. Only need the first 4 columns of your example data:

# text version of the example data
text<-"onset    terminus    tail    head
9/6/2000    9/7/2000    mmmarcantel@equiva.com  matthew.lenhart@enron.com
9/6/2000    9/7/2000    stephen.harrington@enron.com    matthew.lenhart@enron.com
9/6/2000    9/7/2000    shelliott@dttus.com matthew.lenhart@enron.com
9/6/2000    9/7/2000    jilallen@dttus.com  matthew.lenhart@enron.com
5/7/2001    5/8/2001    ken.shulklapper@enron.com   matthew.lenhart@enron.com
9/6/2000    9/7/2000    eric.bass@enron.com matthew.lenhart@enron.com
9/6/2000    9/7/2000    shelliott@dttus.com matthew.lenhart@enron.com
9/6/2000    9/7/2000    bryan.hull@enron.com    matthew.lenhart@enron.com
9/6/2000    9/7/2000    jilallen@dttus.com  matthew.lenhart@enron.com
9/6/2000    9/7/2000    shelliott@dttus.com matthew.lenhart@enron.com
9/6/2000    9/7/2000    brook@pdq.net   matthew.lenhart@enron.com
9/5/2000    9/6/2000    tlenhart@corealty.com   matthew.lenhart@enron.com
9/5/2000    9/6/2000    patrick.ryder@enron.com matthew.lenhart@enron.com
9/5/2000    9/6/2000    eric.bass@enron.com matthew.lenhart@enron.com
9/5/2000    9/6/2000    mmmarcantel@equiva.com  matthew.lenhart@enron.com
5/7/2001    5/8/2001    tlenhart@corealty.com   matthew.lenhart@enron.com
9/5/2000    9/6/2000    tlenhart@corealty.com   matthew.lenhart@enron.com
9/5/2000    9/6/2000    tlenhart@corealty.com   matthew.lenhart@enron.com
9/5/2000    9/6/2000    paul.lucci@enron.com    matthew.lenhart@enron.com
9/5/2000    9/6/2000    jilallen@dttus.com  matthew.lenhart@enron.com
9/5/2000    9/6/2000    tlenhart@corealty.com   matthew.lenhart@enron.com
9/5/2000    9/6/2000    paul.lucci@enron.com    matthew.lenhart@enron.com
9/5/2000    9/6/2000    bryan.hull@enron.com    matthew.lenhart@enron.com
9/5/2000    9/6/2000    shelliott@dttus.com matthew.lenhart@enron.com
8/31/2000   9/1/2000    bryan.hull@enron.com    matthew.lenhart@enron.com
8/31/2000   9/1/2000    tlenhart@corealty.com   matthew.lenhart@enron.com"

# write out the example data to an example input file
inputFile<-tempfile()
cat(text,file=inputFile)

现在,加载网络动态库

library(networkDynamic)

# read in tab-delimited example input file
timeData<-read.csv(inputFile,sep = "\t",stringsAsFactors = FALSE)
# check that it was loaded correctly
timeData

# convert the date formats into a numeric time (milliseconds)
timeData$onset<-as.numeric(as.POSIXct(timeData$onset,format='%m/%d/%Y'))
timeData$terminus<-as.numeric(as.POSIXct(timeData$terminus,format='%m/%d/%Y'))

# create a table of email address to map to numeric ids
emails<-unique(c(timeData$head,timeData$tail))

#covert ids
timeData$head<- match(timeData$head,emails)
timeData$tail<- match(timeData$tail,emails)

# convert to networkDynamic object
enronDyn<-networkDynamic(edge.spells=timeData)

# copy in the network names
network.vertex.names(enronDyn)<-emails

# load ndtv library
library(ndtv)

# compute the animation at 30-day interval
compute.animation(enronDyn,slice.par=list(start=967705200,end=989305200,interval=2592000,aggregate.dur=2592000,rule='latest'))
# render out the animation
render.animation(enronDyn)
ani.replay()

但是,您的输入数据对我来说有点有趣。我很确定,原始的安然电子邮件数据比发送电子邮件的日期具有更精确的时间戳,并且发送一整封电子邮件应该花一整天吗?如果您可以找到具有更精确时间戳的数据版本,则在呈现和分析动态事件方面将具有更大的灵活性。例如,您将知道每天发送电子邮件的顺序,等等。

However, your input data looks a little funny to me. I'm pretty sure the original Enron email data has more precise timestamps than the day the email was sent, and it shouldn't take an entire day to send each email? If you can find a version of the data with a more precise timestamp, you will have much more flexibility with how you render and analyse the dynamic events. For example, you will know the order which the emails were sent each day, etc.

这篇关于如何在R中将数据帧上传到ndtv?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆