How to use R interp1 similarly as MATLAB's?
<p>I am trying to interpolate linearly in R. 
Pseudocode is <code>u = interp1(u, linspace(1, numel(u), numel(u)-1));</code> in MATLAB where extrapolation returns NaN if the point is outside the domain (default, more <a href="https://se.mathworks.com/help/matlab/ref/interp1.html#inputarg_extrapolation" rel="nofollow noreferrer">here</a>). </p>

<ul>
<li><code>approx rule=1</code> is equivalent to MATLAB pseudocode</li>
</ul>

<p>I am not sure about the second <code>interp1</code> parameter what is not required in MATLAB so I just let unsuccessufully <code>y &lt;- x</code> such that </p>

<pre><code>interp1(x, y, xi, method = "linear")
</code></pre>

<p>Minimal code example (real one has > 500 k points so linear will work) and its output at the top </p>

<pre><code>List of 2
 $ : num [1:3] 1 2 3
 $ : num [1:2] 1 2
 num [1:2] 0 1
Error in interp1(x, y, xi, method = "linear") : 
  Points 'xi' outside of range of argument 'x'.
Execution halted

library("pracma") # http://finzi.psych.upenn.edu/library/pracma/html/interp1.html

files &lt;- vector("list", 2)
files[[1]] &lt;- c(1,2,3)
files[[2]] &lt;- c(1,2)
str(files)

# Wanted, MATLAB:  u = interp1(u, linspace(1, numel(u), numel(u)-1));

xi &lt;- seq(0,1, len = length(files[[1]]) - 1)
x &lt;- files[[1]]
y &lt;- files[[1]]
str(xi)

files[[1]] &lt;- interp1(x, y, xi, method = "linear")

str(files)
</code></pre>

<p>I know the thread <a href="https://stackoverflow.com/q/15896299/54964">using interp1 in R for matrix</a> but I do not have a matrix. </p>

<p>Input: <code>c(1,2,3)</code><br>
Expected output: [1:2] datastructure </p>

<p>R: 3.3.1<br>
OS: Debian 8.5   </p>