edge-list

How to extract unique and double records by row while keeping original row order using R?

做~自己de王妃 提交于 2020-01-24 10:45:05
问题 Original (see Update below) I'm a newbie to R and currently working with collaboration data in the form of an edge list with 32 columns and around 200.000 rows in the following representation: 1 A A A B C A 2 A B B B C A 3 A B C C C C 4 B A B A B C A, B, C represent the countries of the in the publication participating researchers' institutions. In the real data set "A" is e.g. a country name such as "England" or "China". I want to keep unique records (A) and double records (A A) but remove

Creating edge list with additional variables in R

妖精的绣舞 提交于 2020-01-06 23:51:37
问题 I have data like this: ID=c(rep("ID1",3), rep("ID2",2), "ID3", rep("ID4",2)) sex=c(rep("male",3), rep("female",2), "female", rep("male",2)) item=c("a","b","c","a","c","a","b","a") df1 <- data.frame(ID,sex,item) df1 ID sex item 1 ID1 male a 2 ID1 male b 3 ID1 male c 4 ID2 female a 5 ID2 female c 6 ID3 female a 7 ID4 male b 8 ID4 male a and I would need it as edges like this: head(nodes) ID sex V1 V2 1 ID1 male a b 2 ID1 male b c 3 ID1 male a c 4 ID2 female a c 5 ID4 male b a With @akrun's kind

How can I cut a tree into two by removing an edge?

戏子无情 提交于 2019-12-13 08:02:02
问题 My goal is for the removal of an edge from a given tree T will result in the formation of two separate trees, T1 and T2. Each vertex of the tree T is assigned a positive integer. My task is to remove an edge, such that the Tree_diff of the resultant trees is minimized. Tree_diff is defined as the following: F(T) = Sum of numbers written on each vertex of a tree T Tree_diff(T) = abs(F(T1) - F(T2)) Input Format: The first line will contain an integer N, i.e. the number of vertices in the tree.

Extract edge and communities from list of nodes

心已入冬 提交于 2019-12-04 03:19:10
问题 I have dataset which has more than 50k nodes and I am trying to extract possible edges and communities from them. I did try using some graph tools like gephi, cytoscape, socnet, nodexl and so on to visualize and identify the edges and communities but the node list too large for those tools. Hence I am trying to write script to exact the edge and communities. The other columns are connection start datetime and end datetime with GPS locations. Input: Id,starttime,endtime,gps1,gps2 0022d9064bc

How to change edges' weight by designated rule?

◇◆丶佛笑我妖孽 提交于 2019-12-03 11:31:12
问题 I have a weighted graph: F=nx.path_graph(10) G=nx.Graph() for (u, v) in F.edges(): G.add_edge(u,v,weight=1) Get the nodes list: [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9)] I want to change each edge's weight by this rule: Remove one node, such as node 5, clearly, edge (4, 5) , and (5, 6) will be delete, and the weight of each edge will turn to: {# these edges are nearby the deleted edge (4, 5) and (5, 6) (3,4):'weight'=1.1, (6,7):'weight'=1.1, #these edges are

How to change edges' weight by designated rule?

夙愿已清 提交于 2019-12-03 01:53:35
I have a weighted graph: F=nx.path_graph(10) G=nx.Graph() for (u, v) in F.edges(): G.add_edge(u,v,weight=1) Get the nodes list: [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9)] I want to change each edge's weight by this rule: Remove one node, such as node 5, clearly, edge (4, 5) , and (5, 6) will be delete, and the weight of each edge will turn to: {# these edges are nearby the deleted edge (4, 5) and (5, 6) (3,4):'weight'=1.1, (6,7):'weight'=1.1, #these edges are nearby the edges above mentioned (2,3):'weight'=1.2, (7,8):'weight'=1.2, #these edges are nearby the edges

Creating edge list with additional variables in R

情到浓时终转凉″ 提交于 2019-12-02 13:24:53
I have data like this: ID=c(rep("ID1",3), rep("ID2",2), "ID3", rep("ID4",2)) sex=c(rep("male",3), rep("female",2), "female", rep("male",2)) item=c("a","b","c","a","c","a","b","a") df1 <- data.frame(ID,sex,item) df1 ID sex item 1 ID1 male a 2 ID1 male b 3 ID1 male c 4 ID2 female a 5 ID2 female c 6 ID3 female a 7 ID4 male b 8 ID4 male a and I would need it as edges like this: head(nodes) ID sex V1 V2 1 ID1 male a b 2 ID1 male b c 3 ID1 male a c 4 ID2 female a c 5 ID4 male b a With @akrun's kind help I could get the V1 and V2 columns with this: lst <- lapply(split(item, DG), function(x) if(length

Extract edge and communities from list of nodes

醉酒当歌 提交于 2019-12-01 17:02:55
I have dataset which has more than 50k nodes and I am trying to extract possible edges and communities from them. I did try using some graph tools like gephi, cytoscape, socnet, nodexl and so on to visualize and identify the edges and communities but the node list too large for those tools. Hence I am trying to write script to exact the edge and communities. The other columns are connection start datetime and end datetime with GPS locations. Input: Id,starttime,endtime,gps1,gps2 0022d9064bc,1073260801,1073260803,819251,440006 00022d9064bc,1073260803,1073260810,819213,439954 00904b4557d3

How to create an edge list from a matrix in R?

走远了吗. 提交于 2019-11-28 09:17:01
The relationship is expressed as a matrix x like this: A B C D A 0 2 1 1 B 2 0 1 0 C 1 1 0 1 D 1 0 1 0 The entries refer to the number of connections they have. Could anyone show me how to write it as an edge list? I would prefer to write it as an edge list: A B A B A C A D B C But would this edge list allow me to create a network plot? flodel Using the igraph package: x <- matrix(c(0,2,1,1,2,0,1,0,1,1,0,1,1,0,1,0), 4, 4) rownames(x) <- colnames(x) <- LETTERS[1:4] library(igraph) g <- graph.adjacency(x) get.edgelist(g) # [,1] [,2] # [1,] "A" "B" # [2,] "A" "B" # [3,] "A" "C" # [4,] "A" "D" #

How to create an edge list from a matrix in R?

て烟熏妆下的殇ゞ 提交于 2019-11-27 02:53:36
问题 The relationship is expressed as a matrix x like this: A B C D A 0 2 1 1 B 2 0 1 0 C 1 1 0 1 D 1 0 1 0 The entries refer to the number of connections they have. Could anyone show me how to write it as an edge list? I would prefer to write it as an edge list: A B A B A C A D B C But would this edge list allow me to create a network plot? 回答1: Using the igraph package: x <- matrix(c(0,2,1,1,2,0,1,0,1,1,0,1,1,0,1,0), 4, 4) rownames(x) <- colnames(x) <- LETTERS[1:4] library(igraph) g <- graph