Note that there are some explanatory texts on larger screens.

plurals
  1. POSplit strings at the first colon
    primarykey
    data
    text
    <p>I am reading data files in text format using <code>readLines</code>. The first 'column' is complicated text that I do not need. The next columns contain data that I do need. The first 'column' and the data are separated by a colon (:). I wish to split each row at the first colon and delete the resulting text string, keeping only the data. </p> <p>Below is an example data file. One potential complication is that one line of data contains multiple colons. That line may at some point become my header. So, I probably should not split at every colon, just at the first colon.</p> <pre><code>my.data &lt;- "first string of text..: aa : bb : cc next string ........ : 2 0 2 third string......1990: 7 6 5 last string : 4 2 3" my.data2 &lt;- readLines(textConnection(my.data)) my.data2 </code></pre> <p>I have tried code presented here:</p> <p><a href="https://stackoverflow.com/questions/10309122/split-on-first-comma-in-string">Split on first comma in string</a></p> <p>and here:</p> <p><a href="https://stackoverflow.com/questions/11127010/r-removing-the-last-three-dots-from-a-string">R: removing the last three dots from a string</a></p> <p>Code at the first link above seems to split only at the first colon of the first row. Code at the second link will probably do what I want, but is too complex for me to modify it successfully so far.</p> <p>Here are the data I hope to obtain, at which point I can simply replace the remaining colons in the first row with empty spaces using a very simple <code>gsub</code> statement:</p> <pre><code> aa : bb : cc 2 0 2 7 6 5 4 2 3 </code></pre> <p>Sorry if this is a duplicate of a post I have not located and thank you for any advice or assistance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload