# [.igraph

0th

Percentile

##### Query and manipulate a graph as it were an adjacency matrix

Query and manipulate a graph as it were an adjacency matrix

##### Usage
## S3 method for class 'igraph':
[(x, i, j, ..., from, to,
sparse = igraph_opt("sparsematrices"), edges = FALSE, drop = TRUE,
attr = if (is_weighted(x)) "weight" else NULL)
##### Arguments
x
The graph.
i
Index. Vertex ids or names or logical vectors. See details below.
j
Index. Vertex ids or names or logical vectors. See details below.
...
Currently ignored.
from
A numeric or character vector giving vertex ids or names. Together with the to argument, it can be used to query/set a sequence of edges. See details below. This argument cannot be present together with any of the i and j
 to A numeric or character vector giving vertex ids or names. Together with the from argument, it can be used to query/set a sequence of edges. See details below. This argument cannot be present together with any of the i and j sparse Logical scalar, whether to return sparse matrices. edges Logical scalar, whether to return edge ids. drop Ignored. attr If not NULL, then it should be the name of an edge attribute. This attribute is queried and returned. 
 
 Details The single bracket indexes the (possibly weighted) adjacency matrix of the graph. Here is what you can do with it:Check whether there is an edge between two vertices ($v$and$w$) in the graph:graph[v, w]A numeric scalar is returned, one if the edge exists, zero otherwise.Extract the (sparse) adjacency matrix of the graph, or part of it:graph[] graph[1:3,5:6] graph[c(1,3,5),]The first variants returns the full adjacency matrix, the other two return part of it.Thefromandtoarguments can be used to check the existence of many edges. In this case, bothfromandtomust be present and they must have the same length. They must contain vertex ids or names. A numeric vector is returned, of the same length asfromandto, it contains ones for existing edges edges and zeros for non-existing ones. Example:graph[from=1:3, to=c(2,3,5)].For weighted graphs, the[operator returns the edge weights. For non-esistent edges zero weights are returned. Other edge attributes can be queried as well, by giving theattrargument.Querying edge ids instead of the existance of edges or edge attributes. E.g.graph[1, 2, edges=TRUE]returns the id of the edge between vertices 1 and 2, or zero if there is no such edge.Adding one or more edges to a graph. For this the element(s) of the imaginary adjacency matrix must be set to a non-zero numeric value (orTRUE):graph[1, 2] <- 1 graph[1:3,1] <- 1 graph[from=1:3, to=c(2,3,5)] <- TRUEThis does not affect edges that are already present in the graph, i.e. no multiple edges are created.Adding weighted edges to a graph. Theattrargument contains the name of the edge attribute to set, so it does not have to beweight:graph[1, 2, attr="weight"]<- 5 graph[from=1:3, to=c(2,3,5)] <- c(1,-1,4)If an edge is already present in the network, then only its weigths or other attribute are updated. If the graph is already weighted, then theattr="weight"setting is implicit, and one does not need to give it explicitly.Deleting edges. The replacement syntax allow the deletion of edges, by specifyingFALSEorNULLas the replacement value:graph[v, w] <- FALSEremoves the edge from vertex$v$to vertex$w$. As this can be used to delete edges between two sets of vertices, either pairwise:graph[from=v, to=w] <- FALSEor not:graph[v, w] <- FALSEif$v$and$w$are vectors of edge ids or names.[ allows logical indices and negative indices as well, with the usual R semantics. E.g. graph[degree(graph)==0, 1] <- 1 adds an edge from every isolate vertex to vertex one, and G <- make_empty_graph(10) G[-1,1] <- TRUE creates a star graph.Of course, the indexing operators support vertex names, so instead of a numeric vertex id a vertex can also be given to [ and [[. Value A scalar or matrix. See details below. See Also Other structural queries: [[.igraph; adjacent_vertices; are.connected, are_adjacent; ecount, gsize; ends, get.edge, get.edges; get.edge.ids; gorder, vcount; head_of; incident_edges; incident; is.directed, is_directed; neighbors; tail_of Aliases [.igraph Documentation reproduced from package igraph, version 1.0.0, License: GPL (>= 2) Community examples Looks like there are no examples yet. Post a new example: 
 
 
 R package Rdocumentation.org Created by DataCamp.com 
 Put your R skills to the test window.MathJax = { tex: { inlineMath: [ ['$','$'], ['\$$','\$$'] ], displayMath: [ ['$$','$$'] ], processEscapes: true, packages: ['base', 'ams', 'noerrors', 'noundefined'] }, options: { ignoreHtmlClass: 'tex2jax_ignore', processHtmlClass: 'tex2jax_process' }, loader: { load: ['[tex]/noerrors'] } }; var $jq = jQuery.noConflict(); ;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[]; p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments) };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1; n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","//cdn.datacamp.com/sp/2.10.2.js","snowplow")); var options = { appId: 'rdocumentation', platform: 'web', post: true, discoverRootDomain: true, contexts: { webPage: true, performanceTiming: true } }; options.forceSecureTracker = true; options.postPath = '/spevent'; window.snowplow('newTracker', 'co', "www.datacamp.com", options); window.snowplow('enableActivityTracking', 10, 10); // Ping every 10 seconds after 10 seconds window.snowplow('enableLinkClickTracking'); window.snowplow('trackPageView', null, [ { schema: 'iglu:com.datacamp/user/jsonschema/1-0-0', data: { anonId:$jq.cookie('dc_aid'), } } ]); var config = { forms: { whitelist: ["snowplow_tracked"] }, fields: { blacklist: ['password', 'password_confirmation'] } }; window.snowplow('enableFormTracking', config); (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-41577880-1', 'rdocumentation.org'); ga('send', 'pageview');