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?
