<p><strong>Question</strong></p>

<blockquote>
  <p>Is it possible to write values of different datatypes to a file in R?
  Currently, I am using a simple vector as follows:</p>

<pre><code>&gt; vect = c (1,2, "string")
&gt; vect
[1] "1"     "2"     "string"
&gt; write.table(vect, file="/home/sampleuser/sample.txt", 
              append= FALSE, sep= "|")
</code></pre>
  
  <p>However, since <code>vect</code> is a vector of string now, opening the file has
  following contents being in quoted form as:</p>

<pre><code>"x"
"1"|"1"
"2"|"2"
"3"|"string"
</code></pre>
  
  <p>Is it not possible to restore the data types of entries <code>1</code> and <code>2</code>
  being treated as numeric value instead of string. So my expected
  result is:</p>

<pre><code>"x"
"1"|1
"2"|2
"3"|"string"
</code></pre>
  
  <p>also, I am assuming the left side values "1", "2" and "3" are vector
  indexes? I did not understand how the first line is "x"?</p>
</blockquote>

<p><strong>Issues</strong></p>

<p>No statistical issues, so Off Topic on CV. On topic on SO, and a good candidate for migration, as the OP has provided a clear explanation of the problem, and simple example code that is easily runnable by others that demonstrates their problem.</p>

<p><strong>Outcome</strong></p>

<p>Migrate to SO.</p>
