Skip to content

combining data structures

4 messages · David Stevens, Pete Brecknock

#
Not entirely sure why you would want a data.frame that has multiple entries
in one of the columns (Connect.down) but leaving that aside is the following
of any use?

nn=list()
    
nn[[1]] =  list(Node = "1", Connect.up = c(NULL), Connect.down = c(2,3))
nn[[2]] =  list(Node = "2", Connect.up = c(1), Connect.down = c(4,5))
nn[[3]] =  list(Node = "3", Connect.up = c(NULL), Connect.down = c(2,3))
nn[[4]] =  list(Node = "4", Connect.up = c(1), Connect.down = c(4,5))

Output = do.call(as.data.frame(rbind),nn)

# Output
  value.Node value.Connect.up value.Connect.down
1          1             NULL               2, 3
2          2                1               4, 5
3          3             NULL               2, 3
4          4                1               4, 5

HTH

Pete



dkStevens wrote
--
View this message in context: http://r.789695.n4.nabble.com/combining-data-structures-tp4356288p4356547.html
Sent from the R help mailing list archive at Nabble.com.
#
David

1. The last line of the code should have been ...

Output = as.data.frame(do.call(rbind,nn))

# Output
  Node Connect.up Connect.down
1    1       NULL         2, 3
2    2          1         4, 5
3    3       NULL         2, 3
4    4          1         4, 5

Apologies for any confusion

2.  I am not familiar with the diagram package or the examples you describe.

Why the desire to create a data frame? Why not just use a list?

HTH

Pete


dkStevens wrote
--
View this message in context: http://r.789695.n4.nabble.com/combining-data-structures-tp4356288p4358435.html
Sent from the R help mailing list archive at Nabble.com.