Building a new matrix for a future edgelist

Hello everyone,

I need to add a column to a matrix. the starting matrix is of the type:
column1 column 2
company name person name

i need to get

column 1 column 2 column 3
company name company name person name

whenever a person is present in two different enterprises ; enterprises that have no connection to others can be deleted.
the whole thing is to create an edgelist for a high size network

Thanks to those who will help me!

  1. No embedded spaces in variable names.
  2. No duplicated variable names.
d <- data.frame(cname = c("A", "B", "C", "D", "E", "F", "G", "H", "I"),
                pname = c("j", "k", "l", "m", "n", "o", "p", "q", "r"))

supp <-  c("J", "K", "L", "M", "N", "O", "P", "Q", "R")
supp
#> [1] "J" "K" "L" "M" "N" "O" "P" "Q" "R"
m <- as.matrix(d)
m <- cbind(m[,1],supp,m[,2])
colnames(m) <- c("cname","cname2","pname")
m
#>       cname cname2 pname
#>  [1,] "A"   "J"    "j"  
#>  [2,] "B"   "K"    "k"  
#>  [3,] "C"   "L"    "l"  
#>  [4,] "D"   "M"    "m"  
#>  [5,] "E"   "N"    "n"  
#>  [6,] "F"   "O"    "o"  
#>  [7,] "G"   "P"    "p"  
#>  [8,] "H"   "Q"    "q"  
#>  [9,] "I"   "R"    "r"

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.