Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

How to repeat elements in c() function?

$
0
0

I am using the combine function c() to define the gradient:

eval_f <- function( x, param, n ) { 
return(list("objective" = x[5] * (param[1] - param[2] / sum(x[1:4])),
             "gradient" =     c( x[5] * param[2] / (x[1] * x[1]), 
                                 x[5] * param[2] / (x[2] * x[2]), 
                                 x[5] * param[2] / (x[3] * x[3]), 
                                 x[5] * param[2] / (x[4] * x[4]),
                                    param[1] - param[2] / sum(x[1:4])  
                           ) ) )
}

One can see the gradient includes elements that have same structure: x[5] * param[2] / (x[...] * x[...])

Question. Is it possible to use a standart function (like rep(c(...), times=n)) to create the gradient?


Viewing all articles
Browse latest Browse all 201867

Trending Articles