Hi,
I'm working with R and I have a code like this:
for (i in 1:10)
for (j in 1:100)
if (data[i] == paths[j,1])
cluster[i,4] <- paths[j,2]
where :
data
is a vector with 100 rows and 1 columnpaths
is a matrix with 100 rows and 5 columnscluster
is a matrix with 100 rows and 5 columns
My question is: how could I avoid the use of "for" loops to iterate through the matrix? I don't know whether apply
functions (lapply, tapply...) are useful in this case.
This is a problem when j=10000 for example, because execution time is very long.
Thank you