title: Append values to a data frame from another data frame, given a condition and improving efficiency of the code in R
body: <p>I have a dataset called <code>train</code>, to which I want to append the values in the columns of <code>total</code>, when the attributes <code>created_at</code> and <code>user_id</code> match in both the datasets.
  The following is the code I have written.</p>
  
  <pre><code>total = read.csv('Data.csv')
  train = read.csv('train.csv', sep='\t')
  
  train$lang=NA
  train$tweet_lang=NA
  train$time_zone=NA
  train$instrumentalness=NA
  train$liveness=NA
  
  for (i in 1:nrow(train))
  {
      train[i,'lang'] = total[which( total$created_at == as.character(train[i,'created_at']) &amp;&amp; total$user_id == as.character(train[i,'user_id']) ),'lang']
      train[i,'tweet_lang'] = total[which( total$created_at == as.character(train[i,'created_at'])&amp;&amp; total$user_id == as.character(train[i,'user_id']) ),'tweet_lang']
      train[i,'time_zone'] = total[which( total$created_at == as.character(train[i,'created_at'])&amp;&amp; total$user_id == as.character(train[i,'user_id']) ),'time_zone']
      train[i,'instrumentalness'] = total[which( total$created_at == as.character(train[i,'created_at'])&amp;&amp; total$user_id == as.character(train[i,'user_id']) ),'instrumentalness']
      train[i,'liveness'] = total[which( total$created_at == as.character(train[i,'created_at'])&amp;&amp; total$user_id == as.character(train[i,'user_id']) ),'liveness']
      }
  </code></pre>
  
  <p>However, for <code>i=3</code>, I get the error: <code>Error in x[...] &lt;- m : replacement has length zero</code>. How can I populate the value in the dataset <code>train</code> even if it is an empty string? 
  Also, this implementation (using loops) is very slow. Is there any way to vectorize or parallelize the code to make it run faster?</p>