# construct network out of a list of panels of varying sizes
# omiting missing day 25
data(windsurferPanels)
dynBeach<-networkDynamic(network.list=beach[-25], vertex.pid="vertex.names",
onsets=c(1:24,26:31),termini=c(2:25,27:32))
# read in tsv files for vertex and edge spells and
# construct network of McFarland classroom interaction data
# see ?cls33_10_16_96 for more info about this data set
# read vertex data
rawVerts<-read.table(paste(path.package('networkDynamic'),
"/extdata/cls33_10_16_96_vertices.tsv",sep=''),header=TRUE)
# peek at column headings to find ids and times
names(rawVerts)
# read in interation (edge) data
rawEdges<-read.table(paste(path.package('networkDynamic'),
"/extdata/cls33_10_16_96_edges.tsv",sep=''),header=TRUE)
# peek at column headings to find ids and times
names(rawEdges)
# construct network using vertex and edge timing information
cls33 <-networkDynamic(vertex.spells=rawVerts[,c(3,4,1)],
edge.spells=rawEdges[,c(3,4,1,2)])
# add in the unchanging vertex attribute data
set.vertex.attribute(cls33,"sex",as.vector(rawVerts$sex))
set.vertex.attribute(cls33,"role",as.vector(rawVerts$role))
if (FALSE) # takes 5 seconds, too slow for CRAN checks
# loop over edge data to add the dynamic attributes on the edge
for(r in 1:nrow(rawEdges)){
# get the id of the edge from its tail and head
eid <- get.edgeIDs(cls33,v=rawEdges$from_vertex_id[r],
alter=rawEdges$to_vertex_id[r])
activate.edge.attribute(cls33,'interaction_type',rawEdges$interaction_type[r],
onset=rawEdges$start_minute[r],terminus=rawEdges$end_minute[r],e=eid)
activate.edge.attribute(cls33,'weight',rawEdges$weight[r],
onset=rawEdges$start_minute[r],terminus=rawEdges$end_minute[r],e=eid)
}
# convert the set of newcomb panels with rank weights
data(newcomb)
newRankDyn <-networkDynamic(network.list=newcomb.rank)
get.network.attribute.active(newRankDyn,'title',at=3)
as.matrix(network.collapse(newRankDyn,at=5),attrname='rank')
Run the code above in your browser using DataLab