title: How to make a column exist in r?
body: <p>I have a very large dataset where I am looking to take a column of identifiers (<code>CP</code>) first edit how the identifiers look to match another file, and then search if there are ```CP`` matches between the files.</p>
  <p>I do the editing of the <code>CP</code> first with:</p>
  <pre><code>fullGWAS &lt;- fread('file.csv',sep=&quot;,&quot;)
  
  colnames(fullGWAS)[1] &lt;- &quot;CP&quot;
  fullGWAS2&lt;-gsub(&quot;_.*&quot;,&quot;&quot;,fullGWAS$CP)
  fullGWAS2 &lt;-data.frame(fullGWAS2)
  colnames(fullGWAS2)[1] &lt;- &quot;CP&quot;
  
  fullGWAS3 &lt;- select(fullGWAS, c(2:15))
  
  gwasdf &lt;- cbind(fullGWAS2, fullGWAS3)
  </code></pre>
  <p>As an example <code>gwasdf</code> looks like:</p>
  <pre><code>&gt; head(gwasdf)
             CP chr     bpos a1 a2   freq BETAsbp    Psbp BETAdbp   Pdbp  BETApp    Ppp    minP
  1   1:2556125   1  2556125  t  c 0.3255 -0.0262 0.41300 -0.0113 0.5388 -0.0157 0.4690 0.41300
  2   1:2556548   1  2556548  t  c 0.3261 -0.0274 0.39270 -0.0121 0.5096 -0.0160 0.4615 0.39270
  3   1:2556709   1  2556709  a  g 0.3257 -0.0263 0.41210 -0.0116 0.5266 -0.0155 0.4749 0.41210
  4 12:11366987  12 11366987  t  c 0.9443  0.0355 0.61460  0.0019 0.9631  0.0185 0.7007 0.61460
  5 17:21949792  17 21949792  a  c 0.4570 -0.0384 0.20690 -0.0043 0.8065 -0.0212 0.3050 0.20690
  6 17:21955349  17 21955349  t  g 0.5253  0.0505 0.09562  0.0103 0.5574  0.0248 0.2303 0.09562
    minTRAIT BETAmean
  1      SBP -0.01875
  2      SBP -0.01975
  3      SBP -0.01895
  4      SBP  0.01870
  5      SBP -0.02135
  6      SBP  0.03040
  </code></pre>
  <p>I can see <code>CP</code> is here yet when I try to check this I get:</p>
  <pre><code>exists(&quot;gwasdf$CP&quot;)
  [1] FALSE
  
  class(gwasdf)
  [1] &quot;data.frame&quot;
  
  nrow(gwasdf)
  [1] 7083535
  </code></pre>
  <p>Why is this false and how can I make it be true?</p>
  <p>I am trying to ultimately check whether the CP identifiers are present in another file with follow-up code using:</p>
  <pre><code>CPmatches &lt;- df2[CP %in% gwasdf$CP]  #df2 is another file I just read in
  
  mismatchextract &lt;- subset(gwasdf, !(CP %in% df2$CP))
  </code></pre>
  <p>For extra info I use RStudio with:</p>
  <pre><code>&gt; sessionInfo()
  R version 4.0.2 (2020-06-22)
  Platform: x86_64-w64-mingw32/x64 (64-bit)
  Running under: Windows 10 x64 (build 18363)
  
  Matrix products: default
  
  locale:
  [1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
  [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
  [5] LC_TIME=English_United Kingdom.1252    
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  other attached packages:
   [1] matrixStats_0.57.0 sqldf_0.4-11       RSQLite_2.2.1      gsubfn_0.7        
   [5] proto_1.0.0        data.table_1.13.2  forcats_0.5.0      stringr_1.4.0     
   [9] dplyr_1.0.2        purrr_0.3.4        readr_1.4.0        tidyr_1.1.2       
  [13] tibble_3.0.4       ggplot2_3.3.2      tidyverse_1.3.0   
  
  loaded via a namespace (and not attached):
   [1] tidyselect_1.1.0 haven_2.3.1      tcltk_4.0.2      colorspace_1.4-1 vctrs_0.3.4     
   [6] generics_0.1.0   chron_2.3-56     blob_1.2.1       rlang_0.4.8      pillar_1.4.7    
  [11] glue_1.4.1       withr_2.3.0      DBI_1.1.0        bit64_4.0.5      dbplyr_2.0.0    
  [16] modelr_0.1.8     readxl_1.3.1     lifecycle_0.2.0  munsell_0.5.0    gtable_0.3.0    
  [21] cellranger_1.1.0 rvest_0.3.6      memoise_1.1.0    fansi_0.4.1      broom_0.7.2     
  [26] Rcpp_1.0.5       scales_1.1.1     backports_1.1.10 jsonlite_1.7.1   fs_1.5.0        
  [31] bit_4.0.4        hms_0.5.3        digest_0.6.27    stringi_1.5.3    grid_4.0.2      
  [36] cli_2.2.0        tools_4.0.2      magrittr_2.0.1   crayon_1.3.4     pkgconfig_2.0.3 
  [41] ellipsis_0.3.1   xml2_1.3.2       reprex_0.3.0     lubridate_1.7.9  assertthat_0.2.1
  [46] httr_1.4.2       rstudioapi_0.13  R6_2.5.0         compiler_4.0.2  
  
  </code></pre>