title: Data manipulation in csv using R
body: <p>I'm currently working with data generated by eyelink. The csv (transformed from asc) is basically one large sequential list, i.e. columns are not created, so for example a row will have 'trial 1' and the following row will have x and y coordinates and the following N rows will also before coming to trail 2 row.</p>
  
  <p>I was wondering if anyone has any advice on how to manipulate this 'stacked' data and transform it into long form data?</p>
  
  <p>Here is what the data looks like when pulled from the csv and into a data frame in R. It only recognises 1 variable with N amount of observations:</p>
  
  <pre><code>&gt; MSG.12892743.start_trial.1.SCNB
  1   12892743      757.0   361.7  5916.0 ... SCNB
  2   MSG 12892744 PreBeep1_1st_Sketchpad SCNB
  3   12892744      756.7   361.7  5920.0 ... SCNB
  4   12892745      756.1   362.2  5924.0 ... SCNB
  5   MSG 12892746 order of frames:   SCNB
  6   12892746      755.8   362.3  5928.0 ... SCNB
  7   12892747      756.7   362.3  5927.0 ... SCNB
  8   MSG 12892748 crosshair  SCNB
  9   12892748      757.8   361.8  5928.0 ... SCNB
  10  12892749      758.4   361.8  5930.0 ... SCNB
  11  MSG 12892750 sketchpad  SCNB
  12  12892750      758.1   361.7  5934.0 ... SCNB
  13  12892751      758.3   361.7  5938.0 ... SCNB
  14  MSG 12892752 sketchpad  SCNB
  15  12892752      759.1   361.9  5948.0 ... SCNB
  16  12892753      760.4   362.7  5956.0 ... SCNB
  17  MSG 12892754 sketchpad  SCNB
  </code></pre>
  
  <p>Ideally I'd like to have individual columns for:</p>
  
  <ul>
  <li>Trial ID (SCNB shown above)</li>
  <li>Frame ID (PreBeep1_1st_Sketchpad above)</li>
  <li>X-CoOr (757.0 above)</li>
  <li>Y-CoOr (361.7 above)</li>
  <li>Time (5916.0 above)</li>
  </ul>
  
  <p>Edit: Example of raw data as requested:</p>
  
  <pre><code>MSG 5410895 start_trial                         
  MSG 5410895 PreBeep1_1st_Sketchpad                          
  5410895 651.6   524.6   4372    ...             
  5410896 651.6   525.3   4376    ...             
  MSG 5410897 order of frames:                            
  5410897 651.7   525.5   4377    ...             
  5410898 651.8   525.9   4378    ...             
  MSG 5410899 crosshair                           
  5410899 652.1   526.1   4376    ...             
  5410900 652.5   526 4373    ...             
  MSG 5410901 sketchpad                           
  5410901 653 525.6   4370    ...             
  5410902 652.2   525.3   4366    ...             
  MSG 5410903 sketchpad                           
  5410903 651.1   524.7   4364    ...             
  5410904 650.9   524.2   4366    ...             
  MSG 5410905 sketchpad                           
  5410905 651.6   523.7   4368    ...             
  5410906 651.8   524 4369    ...             
  MSG 5410907 buffer1                         
  5410907 651.3   524.7   4373    ...             
  5410908 650.7   525.4   4377    ...             
  5410909 651.2   525.9   4383    ...             
  MSG 5410910 Diode1                          
  5410910 651.7   525.5   4384    ...             
  5410911 652.1   525.4   4378    ...             
  5410912 652 525.5   4372    ...             
  5410913 651.9   526 4365    ...             
  5410914 651.8   526.3   4363    ...             
  5410915 651.6   527 4362    ...             
  5410916 651.5   527.7   4362    ...             
  5410917 652 528.6   4365    ...             
  5410918 652.5   528.8   4369    ...             
  5410919 653 528.3   4371    ...             
  5410920 652.9   527.1   4371    ...             
  5410921 652.8   525.9   4371    ...             
  5410922 652.8   524.3   4378    ...             
  5410923 652.3   523.1   4388    ...             
  5410924 651.9   522.7   4397    ...             
  5410925 651.1   523.4   4398    ...             
  5410926 650.9   524.3   4399    ...             
  5410927 650.7   524.2   4397    ...             
  5410928 650.8   524.1   4395    ...             
  5410929 650.8   524 4394    ...             
  5410930 650.7   525.3   4386    ...             
  5410931 651.2   526.4   4379    ...             
  5410932 651.9   527.3   4372    ...             
  5410933 652.7   526.5   4374    ...             
  5410934 652.8   525.6   4375    ...             
  5410935 653 524.8   4376    ...             
  5410936 653.2   524.6   4376    ...             
  5410937 653.5   524.6   4373    ...             
  5410938 653.5   524.7   4372    ...             
  5410939 652.9   524.7   4371    ...             
  5410940 652.1   525.7   4372    ...             
  5410941 651.2   526.6   4372    ...             
  5410942 651.1   527.5   4372    ...             
  5410943 651.2   527.9   4372    ...             
  5410944 651.1   528.7   4373    ...             
  5410945 650.9   529.4   4374    ...             
  5410946 651 528.7   4374    ...             
  5410947 651.2   527.7   4374    ...             
  5410948 651.5   525.7   4374    ...             
  5410949 651.4   524.8   4374    ...             
  5410950 651.3   525.2   4375    ...             
  5410951 651 526.4   4376    ...             
  5410952 650.7   527.4   4382    ...             
  5410953 650.5   527.2   4389    ...             
  5410954 650.6   527 4396    ...             
  5410955 650.6   527.1   4394    ...
  </code></pre>
  
  <p>Delimiters are \t in the csv file if that helps.</p>
  
  <p>As can be seen the data is written row-after-row sequentially from top-to-bottom instead of being organised into columns as I want to shape them.</p>
  
  <p>I've reshaped from short to long before but have no idea where to start with this.</p>
  
  <p>Thanks for taking the time to read.</p>