Dear all,

I am working on an author network and to do so I have to arrange a data.frame (tutu) crossing author names (rows) per publication number (column). The participation of the author to a study is indicated by a 1 and 0 otherwise.

I have a vector (xaulist) of all the names of authors and a data.frame (tata) with all the publications in row and the authors in columns. I have writen a loop to obtain my data.frame but it takes a long time when the number of studies increases. I was looking for a more efficient code.

Here is a minimal working example (my code is terrible i know...):

#---------------------------------------------------------------------------------

au1 <- c('deb', 'art', 'deb', 'seb', 'deb', 'deb', 'mar', 'mar', 'joy', 'deb')
au2 <- c('art', 'deb', 'soy', 'deb', 'joy', 'ani', 'deb', 'deb', 'nem', 'mar')
au3 <- c('mar', 'lio', 'mil', 'mar', 'ani', 'lul', 'nem', 'art', 'deb', 'tat')

tata <- data.frame(au1, au2, au3)
xaulist2 <- levels(factor(unlist(tata[,])))
xaulist <- levels(as.factor(xaulist2))

tutu <- matrix(NA, nrow=length(xaulist), ncol=dim(tata)[1]) # row are authors and col are papers
for (i in 1:length(xaulist))
{
  for (j in 1:dim(tata)[1])
  {
  ifelse('TRUE' %in% as.character(tata[j,]==xaulist[i]), tutu[i,j] <- 1,  tutu[i,j] <- 0)
  }
}
tutu[is.na(tutu)] <- 0

#---------------------------------------------------------------------------------

I am looking at some more efficient way to build 'tutu'.

Thank you very much,

 
David

	[[alternative HTML version deleted]]

