Добавьте атрибуты к объекту igraph, проанализировав фрейм данных - PullRequest
0 голосов
/ 26 мая 2018

Я создаю объект igraph из списка ребер, а затем добавляю атрибуты к узлам.

    library(tidyverse)
    require(dplyr)
    library(readr)
    library(igraph)


#edge list    
    edge_df <- read.table("https://raw.githubusercontent.com/pranavn91/PhD/master/Expt/100129275726588145876.edges", header = F, sep = " ", numerals="no.loss")

#attributes     

    full_ego_friends_feat_circles_df <- read.table("https://raw.githubusercontent.com/pranavn91/PhD/master/Expt/100129275726588145876.feat", header = F, numerals="no.loss")

#names of different attributes

    feat_desc_file_df <- readLines("https://raw.githubusercontent.com/pranavn91/PhD/master/Expt/100129275726588145876.featnames")

    column_names <- append("nodeid",feat_desc_file_df)
    colnames(full_ego_friends_feat_circles_df)<-column_names

 #create a graph from edge list   

    g <- graph_from_data_frame(edge_df, directed = TRUE)

#add attribute to nodes by searching and matching

    V(g)$"0 gender:1"=full_ego_friends_feat_circles_df$"0 gender:1"[match(as.numeric(V(g)$name),as.numeric(levels(full_ego_friends_feat_circles_df$nodeid))[full_ego_friends_feat_circles_df$nodeid]
    )]

Первый атрибут в кадре данных (feat_desc_file_df) - это «0 пол: 1», который добавляется.Но в кадре данных (feat_desc_file_df) есть 1318 имен атрибутов.Для каждого из них я должен искать и сопоставлять, поскольку у меня есть "0 пол: 1", что является лучшим способом

...