0

I have two data sets, I want to match the postIDs and then concatenate the strings. newfile contains 40,500 rows and df2 contains 226,000 rows

library(pracma)
for(i in 1:nrow(newfile))
{
  for(j in 1:nrow(df2))
  {
    if(newfile[i,1]==df2[j,6])
    {
      newfile[i,3]= strcat(newfile[i,3], df2[j,4], collapse = " ")
    }
  }
}

newfile[i,1] is postid for newfile and df2[j,6] is postid for df2 matrix.

newfile[i,3] is text for newfile and df2[j,4] is text for df2.

I wish to concatenate the two strings if post id matches. The problem is the amount of rows in df2 and newfile makes the R go unresponsive.

Looking for any suggestion on string concatenation in R. I am also open to suggestions if I need to change from matrix to some other data type. Already tried data frame and it failed.

Sjon
  • 4,989
  • 6
  • 28
  • 46
  • 1
    Why not use `merge()` data.frames then use `paste()` on 2 columns? – zx8754 Oct 29 '15 at 21:31
  • I am not sure but I bet that there is an easier way to do that. A piece of the two data frames you use can be very useful to try code and help you. – SabDeM Oct 29 '15 at 21:38
  • [How to make a great R reproducible example?](http://stackoverflow.com/questions/5963269) , also read about merge - [How to join (merge) data frames (inner, outer, left, right)?](http://stackoverflow.com/questions/1299871) – zx8754 Oct 29 '15 at 21:43

0 Answers0