title: Transforming a list of strings into a data.frame in a tidy manner
body: <p>I'm wondering if anyone has any tips/tricks on how to handle transforming data, like what is below:</p>
  
  <pre><code>library(tidyverse)
  example.list = list(" 1 North Carolina State University at Raleigh         15       9    12    13     22    15    32    19   14    20    12     17    19    20     19     25     283", 
      " 2 Iowa State University                                9      8     5    11     14     4    11    13   14      9   15     28    14      9    18     27     209", 
      " 3 University of Wisconsin-Madison                      5      6    14     9     20    13    15    12   13      9   13     10    13    24     15     17     208", 
      " 4 Stanford University*                               10      12    14     6      9    10     5     9   13      7   13     10     4      9    23       6    160", 
      " 5 Texas A &amp; M University-College Station               6     12    18    10      7     4     5    11   16    18    10      7    15      4     8       8    159", 
      " 9 University of Michigan-Ann Arbor                     8      5     3     3      8     9    12    11    7    11    13      9     8    11     13       9    140", 
      "10 University of California-Los Angeles                 2      2     2     6      9     7     9     8    7    11    11      8     6    12     13     10     123", 
      "19 Rice University                                      3      3     5    11      4     7     7    11    2      6     4     6     3      8     7       7     94")
  </code></pre>
  
  <p>Into something like the output here:</p>
  
  <pre><code>example.list %&gt;%
      substring(3) %&gt;% 
      str_replace_all("[^[:alnum:]]", " ") %&gt;%
      str_squish() %&gt;% 
      strsplit(split = "(?&lt;=[a-zA-Z])\\s*(?=[0-9])", perl = TRUE) %&gt;% 
      unlist() %&gt;% 
      matrix(ncol = 2, byrow = TRUE) %&gt;% 
      data.frame() %&gt;% 
      separate("X2",into = paste0("X",2:18),sep = " ") 
  </code></pre>
  
  <p>The general pattern that needs extracted is all characters into its own column up to the first numbers, with all other columns separated by whitespace into other columns.</p>
  
  <p>Things that would be interesting is whether most of this could be done in a single regex pattern or without it at all.</p>
  
  <p>I'm just looking to improve string handling as I haven't worked with it much!  The use-case here would be like trying to pull tabled data from a pdf/html into a data.frame.</p>
  
  <p>Edit:</p>
  
  <p>I appreciate all of the advice and different perspectives!</p>
  
  <p>I realized I actually missed a few worthy-of-mention test cases:</p>
  
  <pre><code>example2.list = list(" 2 Iowa State University                                9      8     5    11     14     4    11    13   14      9   15     28    14      9    18     27     209", 
      " 3 University of Wisconsin-Madison                      5      6    14     9     20    13    15    12   13      9   13     10    13    24     15     17     208", 
      " 4 Stanford University*                               10      12    14     6      9    10     5     9   13      7   13     10     4      9    23       6    160", 
      " 5 Texas A &amp; M University-College Station               6     12    18    10      7     4     5    11   16    18    10      7    15      4     8       8    159", 
      " 9 University of Michigan-Ann Arbor                     8      5     3     3      8     9    12    11    7    11    13      9     8    11     13       9    140", 
      "10 University of California-Los Angeles                 2      2     2     6      9     7     9     8    7    11    11      8     6    12     13     10     123", 
      "19 Rice University                                      3      3     5    11      4     7     7    11    2      6     4     6     3      8     7       7     94", 
      "52 Bowling Green State University             0 0 0 0 0 1 5 2 2 2  4 7 3  4  4  3 37", 
      "55 University of New Mexico                   4 2 3 1 3 0 5 3 2 1  1 2 3  2  3  0 35")
  </code></pre>
  
  <p>It doesn't actually come out as neatly as aligned.</p>
  
  <p>Full dataset, slightly cleaned:</p>
  
  <pre><code>library(pdftools)
  library(tidyverse)
  data.loc = "https://ww2.amstat.org/misc/StatsPhD2003-MostRecent.pdf"
  data.full =
      pdf_text(data.loc) %&gt;%
      read_lines() %&gt;%
      head(-2) %&gt;%
      tail(-3) %&gt;%
      lapply(function(ele) if(ele == "") NULL else ele) %&gt;% 
      compact()
  </code></pre>
  
  <p>Here was my second attempt:</p>
  
  <pre><code>library(tidyverse)
  library(magrittr)
    # Ignores column names
    data.full[-1] %&gt;%
    # Removing excess whitepace
    str_squish() %&gt;%
    # Removes index
    str_remove("^\\s*\\d*\\s*") %&gt;%
    # Split on all whitespace occurring before digits
    str_split("\\s+(?=\\d)") %&gt;%
    # Turn list into a matrix
    unlist() %&gt;%
    matrix(ncol = 18, byrow = TRUE) %&gt;%
    # Handling variables names
    set_colnames(value =
                   data.full[1] %&gt;%
                   str_squish() %&gt;%
                   str_split("\\s+(?=\\d)") %&gt;%
                   unlist) %&gt;%
    as_tibble() %&gt;%
    # Transformating variables into  numeric
    type_convert()
  </code></pre>