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: Enter image details here

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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -