0

I have a list users_vs_tags which has users' highest liked tags in descending order. I have a data frame users_vs_items indicating which items users have liked in the past. I have a data frame items_vs_tags indicating which items are related to which tags. I want to generate a data frame ranked_users_vs_items, in which will items will be given a good rank if a user hasn't liked an item among his most liked tags.I have written a code.

for(i in names(users_vs_tags))
{counter<-1
 for(j in colnames(users_vs_tags[[i]]))
 {
  for(k in rownames(items_vs_tags))
  {
   if((items_vs_tags[['k']][['j']]==1)&(users_vs_items[['i']][['k']]==0))
   {
      ranked_users_vs_items[['i']][['k']]<-counter
      counter<-counter+1          
    }

   }
  }
}

Using this nested for loop, I should be able to rank the items for a particular user based on non-liked item history and liked tag history. However one should never use nested for loops in R since they are very slow. I was thinking about using lapply but couldn't think of a way of using it. Could anybody guide me in the right direction?

Ronnie Day
  • 121
  • 2
  • 13
  • 4
    Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – zx8754 Jun 20 '16 at 12:43
  • Perhaps this is enough [guidance](http://stackoverflow.com/questions/2908822/speed-up-the-loop-operation-in-r)? – Christoph Jun 20 '16 at 12:44
  • Reproducible sample data would be key here. – Bryan Goggin Jun 20 '16 at 15:55

0 Answers0