title: Error while copying a column of one dataframe to another in R
body: <p>I am trying to replace the column "X" of dataframe <em>df1</em> by column "X" of dataframe <em>df2</em>. I use the below code:</p>
  
  <pre><code>df1$X &lt;- df2$X
  </code></pre>
  
  <p>The above line of code works well in RStudio environment. However, when I run the R script on my Ubuntu VM from command line and load the dataframes by CSV files fetched from hdfs, the above line of code gives the below error:</p>
  
  <blockquote>
    <p>Error in <code>$&lt;-.data.frame</code>(<code>*tmp*</code>, "X", value = c(3.688879454,  :<br>
    replacement has 1464 rows, data has 161</p>
  </blockquote>
  
  <p>I tried different indexing methods and solutions from google but could not solve it. I am guessing the issue might be because column "X" of df1 has some missing values. I cannot find a solution to fix this.</p>
  
  <p>Here is the code prior to the line of code in question:</p>
  
  <pre><code>require(rhdfs)
  hdfs.init()
  f = hdfs.file(file_input,"r",buffersize=104857600)
  m = hdfs.read(f)
  con = rawToChar(m)
  Df1 = read.table(textConnection(con), sep = ",",header=TRUE, fill = TRUE)
  
  f1 = hdfs.file(file_input1,"r",buffersize=104857600)
  m1 = hdfs.read(f1)
  con1 = rawToChar(m1)
  df2 = read.table(textConnection(con1), sep = ",",header=TRUE, fill = TRUE)
  
  Df1$X &lt;- df2$X
  </code></pre>