# [R] If cycle takes to much time...

marcoguerzoni marco.guerzoni at unito.it
Fri Jan 25 10:25:51 CET 2013

```dear all,

I have a dataset of artists and where and when they had an exhibition.
I'd like to create an affiliation network in the form of matrix, telling me
which aritist have been in the same at the same time.
I manage to do it, but given that I have 96000 observation the program takes
30 months to complete.
her what i have done.
the data look like this

Artist <-c(1,2,3,2,4,4,5)
Begin <- as.Date(c('2006-08-23', '2006-03-21', '2006-03-06', '2006-01-13',
'2006-05-20', '2006-07-13', '2006-07-20'))
End <- as.Date(c('2006-10-23', '2006-11-30', '2006-05-06', '2006-12-13',
'2006-09-20', '2006-08-13', '2006-09-20'))
Istitution <- c(1, 2, 2, 1, 1, 2, 1)

artist is the name of the artist, Begin and End is the when and Istitutionis
the where.

my IF is working,

#number of unique artist
c <- unique(Artist)
d <- length(c)
a <-length(Artist)

B <- mat.or.vec(d,d)

for(i in 1:d) {
for(j in 1:d) {
if (Istitution[i]  == Istitution[j]) {

if (Begin[i] <= End[j])
{
if (End[i]-Begin[j] >= 0) {
B[i,j] <- B[i,j]+1
B[i,i] <- 0

}

}
else{
if (End[j]-Begin[i] >= 0) {
B[i,j] <- B[i,j]+1
B[i,i] <- 0

}
}
}
}
print(i)
}

do you have a way to make the programm simpler and faster?

thank you very much

Marco Guerzoni,
Department of Economics
University of Turin

--
View this message in context: http://r.789695.n4.nabble.com/If-cycle-takes-to-much-time-tp4656601.html
Sent from the R help mailing list archive at Nabble.com.

```