title: Convert a character string to the same type as another object
body: <p>I have a character string, and I want to convert it to the same type as another object. You can assume this object is a vector. For example, given a string <code>"50"</code>, and a target vector <code>1:10</code>, I want <code>"50"</code> to be converted to an integer <code>50</code>. I wonder if there is a generic way to do the conversion. It is simple if I know which type I want to convert it to, e.g. I can use <code>as.numeric()</code> if I want it to be a number.</p>
  
  <p>The background of this question is: I want to provide a graphical user interface so users can edit a value in a table. After they edit a cell, I will get a character string, and I know the original data (typically a matrix or a data frame). I want to update the original data with this new value. I cannot simply do <code>data[i, j] &lt;- value</code> because <code>value</code> is a character string.</p>
  
  <p>I could enumerate a few most common types (e.g. numeric, character, factor, date, ...) and use <code>as.*()</code> to do the conversion, but I'd prefer not to go this way if there is an existing generic approach. Things can be a little tricky for dates (timezone, origin) and factors (may add a new level).</p>