0

I am writing a piece of code that looks up a 2 letter string (variable y) in another data frame column of strings(test4$names) for each app(variable e)

I am trying to use lists instead of rbind to join each data frame created in the inner loop (x)

for (e in b) {
  bi_grams_3 <- bi_final[which(bi_final$app == e),c(1,3)]
  test_4 <- test_1[which(test_1$app == e),c(1,3,5)]
  
  for(c in 1:nrow(bi_grams_3))
  {
    
      y <-as.character(bi_grams_3[c,1])
      aa <- intersect(
        grep(word(y,1),test_4$names),
        grep(word(y,2),test_4$names)
      )
      
      x <- test_4[aa,]
      x$root <- y
      dat_list[[c]] <- x
      
      #x_all <- rbind(x,x_all)
      
    }
    fin_list[[e]] <- dat_list
  
    n=n+1
  message(paste(n,e))
  
}  

However, it is not giving me the same result as rbind in the output (x_all). I am getting some extra values in the fin_list (for all except the 1st app).

Also. How can I later rbind the results to get a dataframe?

jaskaybp
  • 3
  • 1
  • 2
    It would really help if we knew anything about these variables you mention. Please make this question *reproducible* by including unambiguous sample data (using `dput` or `data.frame(...)`) and your expected output (similar/same format). Thanks! – r2evans Jun 22 '20 at 20:20
  • Please take a look at [how to make a great reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Martin Gal Jun 22 '20 at 21:46

0 Answers0