title: Plotting and Linear Regression models with R
body: <p>I am working a homework project for R, I have a CSV file that i need to import, so some analysis on and create a scatter plot and linear regression.</p>
  
  <p>At one point my code has an error, and I am not sure why or where, I think it might be in this line:</p>
  
  <pre><code>x &lt;- c("Name", "Washington")
  
  CTD &lt;- subset (Current_Data, grepl(paste(x, collapse = "|"), Current_Data$V1))
  </code></pre>
  
  <p>So i am new to R, this being the first class i've taken, I googled some and did find one thread on here that had some insight, but even using that code, i still get errors. (<a href="https://stackoverflow.com/questions/55787681/linear-regression-analysis-of-population-data-with-r">Linear Regression Analysis of population data with R</a>)</p>
  
  <p>in talking with others from my class and my professor i went another route, though i'm not sure which is better.</p>
  
  <p>Here is the current code i am using.:</p>
  
  <pre><code>Current_Data&lt;-read.csv("Statepop.csv",header=F,stringsAsFactors=FALSE)
  
  Current_Data
  
  x &lt;- c("Name", "Washington")
  
  CTD &lt;- subset (Current_Data, grepl(paste(x, collapse = "|"), Current_Data$V1))
  
  CTD
  
  C_T_D &lt;- t(CTD)
  
  C_T_D
  
  colnames(C_T_D) &lt;- c("Year","Population")
  </code></pre>
  
  <p>Current_Data is perfect (though that is just reading the CSV)
  but when i get to CTD is where i think something in broken.</p>
  
  <p>CTD gives me this responce</p>
  
  <pre><code>    V1      V2      V3      V4      V5      V6      V7      V8      V9     V10
  54 Washington 6742902 6821655 6892876 6962906 7052439 7163543 7294680 7425432 7535591
  </code></pre>
  
  <p>the problem here is it has not dropped the years, so when i go to take the row and make it to columns with the "t()" function (C_D_T)</p>
  
  <p>i get this:</p>
  
  <blockquote>
    <p>C_T_D
        54<br>
    V1  "Washington"
    V2  "6742902"<br>
    V3  "6821655"<br>
    V4  "6892876"<br>
    V5  "6962906"<br>
    V6  "7052439"<br>
    V7  "7163543"<br>
    V8  "7294680"<br>
    V9  "7425432"<br>
    V10 "7535591"   </p>
  </blockquote>
  
  <p>since i've lost the years, the Colnames does not work and gives me this error:</p>
  
  <blockquote>
    <p>colnames(C_T_D) &lt;- c("Year","Population")
    Error in dimnames(x) &lt;- dn : 
      length of 'dimnames' [2] not equal to array extent</p>
  </blockquote>
  
  <p>EDIT: this is the out put from Current_Data.</p>
  
  <blockquote>
    <p>Current_Data
                         V1        V2        V3        V4        V5        V6        V7        V8        V9       V10
    1                  NAME      2010      2011      2012      2013      2014      2015      2016      2017      2018
    2         United States 309326085 311580009 313874218 316057727 318386421 320742673 323071342 325147121 327167434
    3      Northeast Region  55380645  55600532  55776729  55907823  56015864  56047587  56058789  56072676  56111079
    4        Midwest Region  66974749  67152631  67336937  67564135  67752238  67869139  67996917  68156035  68308744
    5          South Region 114867066 116039399 117271075 118393244 119657737 121037542 122401186 123598424 124753948
    6           West Region  72103625  72787447  73489477  74192525  74960582  75788405  76614450  77319986  77993663
    7               Alabama   4785448   4798834   4815564   4830460   4842481   4853160   4864745   4875120   4887871
    8                Alaska    713906    722038    730399    737045    736307    737547    741504    739786    737438
    9               Arizona   6407774   6473497   6556629   6634999   6733840   6833596   6945452   7048876   7171646
    10             Arkansas   2921978   2940407   2952109   2959549   2967726   2978407   2990410   3002997   3013825
    11           California  37320903  37641823  37960782  38280824  38625139  38953142  39209127  39399349  39557045
    12             Colorado   5048281   5121771   5193721   5270482   5351218   5452107   5540921   5615902   5695564
    13          Connecticut   3579125   3588023   3594395   3594915   3594783   3587509   3578674   3573880   3572665
    14             Delaware    899595    907316    915188    923638    932596    941413    949216    957078    967171
    15 District of Columbia    605085    619602    634725    650431    662513    675254    686575    695691    702455
    16              Florida  18845785  19093352  19326230  19563166  19860330  20224249  20629982  20976812  21299325
    17              Georgia   9711810   9801578   9901496   9973326  10069001  10181111  10304763  10413055  10519475
    18               Hawaii   1363963   1379252   1394905   1408453   1414862   1422484   1428105   1424203   1420491
    19                Idaho   1570773   1583828   1595441   1611530   1631479   1651523   1682930   1718904   1754208
    20             Illinois  12840762  12867291  12884119  12898269  12888962  12864342  12826895  12786196  12741080
    21              Indiana   6490436   6516045   6537640   6568367   6593533   6608296   6633344   6660082   6691878
    22                 Iowa   3050767   3066054   3076097   3093078   3109504   3121460   3131785   3143637   3156145
    23               Kansas   2858213   2869035   2885361   2893510   2900896   2909502   2911263   2910689   2911505
    24             Kentucky   4348200   4369488   4386381   4404817   4414483   4425999   4438229   4453874   4468402
    25            Louisiana   4544532   4575184   4600814   4624577   4644204   4664851   4678215   4670818   4659978
    26                Maine   1327632   1328150   1327691   1328196   1330760   1328484   1331370   1335063   1338404
    27             Maryland   5788642   5838991   5887072   5923704   5958165   5986717   6004692   6024891   6042718
    28        Massachusetts   6566431   6613149   6663158   6713944   6763652   6795891   6826022   6863246   6902149
    29             Michigan   9877535   9881521   9896930   9913349   9930589   9932573   9951890   9976447   9995915
    30            Minnesota   5310843   5345668   5376550   5413693   5451522   5482503   5523409   5568155   5611179
    31          Mississippi   2970536   2978470   2983767   2988797   2990623   2988693   2988298   2989663   2986530
    32             Missouri   5995976   6009641   6024081   6040658   6056293   6071745   6087203   6108612   6126452
    33              Montana    990722    997221   1003754   1013564   1021891   1030503   1040863   1053090   1062305
    34             Nebraska   1829536   1840538   1853323   1865414   1879522   1891507   1905924   1917575   1929268
    35               Nevada   2702464   2712799   2744566   2776972   2819012   2868666   2919772   2972405   3034392
    36        New Hampshire   1316777   1319815   1323962   1326408   1333223   1336294   1342373   1349767   1356458
    37           New Jersey   8799624   8827783   8845483   8858362   8866780   8870869   8874516   8888543   8908520
    38           New Mexico   2064588   2080395   2087549   2092792   2090342   2090211   2092789   2093395   2095428
    39             New York  19400080  19498514  19574549  19628043  19656330  19661411  19641589  19590719  19542209
    40       North Carolina   9574293   9656754   9749123   9843599   9933944  10033079  10156679  10270800  10383620
    41         North Dakota    674710    685136    701116    721999    737382    754022    754353    755176    760077
    42                 Ohio  11539327  11543463  11548369  11576576  11602973  11617850  11635003  11664129  11689442
    43             Oklahoma   3759632   3787821   3818600   3853205   3878367   3909831   3926769   3932640   3943079
    44               Oregon   3837532   3871728   3899118   3922908   3964106   4016918   4091404   4146592   4190713
    45         Pennsylvania  12711158  12744583  12766827  12776621  12789101  12785759  12783538  12790447  12807060
    46         Rhode Island   1053938   1053536   1054601   1055122   1056017   1056173   1057063   1056486   1057315
    47       South Carolina   4635656   4671422   4717112   4764153   4823793   4892253   4958235   5021219   5084127
    48         South Dakota    816165    823484    833496    842270    849088    853933    862890    873286    882235
    49            Tennessee   6355301   6397410   6451281   6493432   6540826   6590808   6645011   6708794   6770010
    50                Texas  25242679  25646227  26089620  26489464  26977142  27486814  27937492  28322717  28701845
    51                 Utah   2775334   2814216   2853467   2897927   2937399   2982497   3042613   3103118   3161105
    52              Vermont    625880    626979    626063    626212    625218    625197    623644    624525    626299
    53             Virginia   8023680   8100469   8185229   8253053   8312076   8362907   8410946   8465207   8517685
    54           Washington   6742902   6821655   6892876   6962906   7052439   7163543   7294680   7425432   7535591
    55        West Virginia   1854214   1856074   1856764   1853873   1849467   1841996   1830929   1817048   1805832
    56            Wisconsin   5690479   5704755   5719855   5736952   5751974   5761406   5772958   5792051   5813568
    57              Wyoming    564483    567224    576270    582123    582548    585668    584290    578934    577737
    58          Puerto Rico   3721525   3678732   3634488   3593077   3534874   3473166   3406495   3325001   3195153</p>
  </blockquote>