graph.data.frame           package:igraph           R Documentation

_C_r_e_a_t_i_n_g _i_g_r_a_p_h _g_r_a_p_h_s _f_r_o_m _d_a_t_a _f_r_a_m_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     This function creates an igraph graph from one or two data frames
     containing the (symbolic) edge list and edge/vertex attributes.

_U_s_a_g_e:

     graph.data.frame(d, directed=TRUE, vertices=NULL)

_A_r_g_u_m_e_n_t_s:

       d: A data frame containing a symbolic edge list in the first two
          columns. Additional columns are considered as edge
          attributes.

directed: Logical scalar, whether or not to create a directed graph.

vertices: A data frame with vertex metadata, or 'NULL'. See details
          below.

_D_e_t_a_i_l_s:

     'graph.data.frame' creates igraph graphs from one or two data
     frames. It has two modes of operatation, depending whether the
     'vertices' argument is 'NULL' or not.

     If 'vertices' is 'NULL', then the first two columns of 'd' are
     used as a symbolic edge list and additional columns as edge
     attributes. The names of the attributes are taken from the names
     of the columns.

     If 'vertices' is not 'NULL', then it must be a data frame giving
     vertex metadata. The first column of 'vertices' is assumed to
     contain symbolic vertex names, this will be added to the graphs as
     the ''name'' vertex attribute. Other columns will be added as
     additional vertex attributes. If 'vertices' is not 'NULL' then the
     symbolic edge list given in 'd' is checked to contain only vertex
     names listed in 'vertices'.

     Typically, the data frames are exported from some speadsheat
     software like Excel and are imported into R via 'read.table',
     'read.delim' or 'read.csv'.

_V_a_l_u_e:

     An igraph graph object.

_A_u_t_h_o_r(_s):

     Gabor Csardi csardi@rmki.kfki.hu

_S_e_e _A_l_s_o:

     'graph.constructors' and 'graph.formula' for other ways to create
     graphs, 'read.table' to read in tables from files.

_E_x_a_m_p_l_e_s:

     ## A simple example with a couple of actors
     ## The typical case is that these tables are read in from files....
     actors <- data.frame(name=c("Alice", "Bob", "Cecil", "David",
                                 "Esmeralda"),
                          age=c(48,33,45,34,21),
                          gender=c("F","M","F","M","F"))
     relations <- data.frame(from=c("Bob", "Cecil", "Cecil", "David",
                                    "David", "Esmeralda"),
                             to=c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice"),
                             same.dept=c(FALSE,FALSE,TRUE,FALSE,FALSE,TRUE),
                             friendship=c(4,5,5,2,1,1), advice=c(4,5,5,4,2,3))
     g <- graph.data.frame(relations, directed=TRUE, vertices=actors)
     print(g, e=TRUE, v=TRUE)

