Writing a function that operates on a vector in R -
I'm trying to run the following function on a vector (t) but I get the following error: < / P>
rho.prime & lt; - function (t, k = 19000) {for (i seq (1, length (t)) {if (abs (t [i]) & lt; = k} {print (2 * t [i]) Returns (2 * t [i]) otherwise {print (2 * k * symbol (t [i]) returns (2 * k * sign (t [i]))}}} Here is the rho.prime function description:
problem It is that I have doubts about the result:
& gt; T = C (1,3,5,7,10)> T [1] 1 3 5 7 10 & gt; Rho.prime (t, k) [1] 2 [1] 2
The function may look like this:
rho < -function (t, k) ifelse (abs (t) & lt; = k, t ^ 2, (2 * k * abs (t)) -k ^ 2)
Comments
Post a Comment