lundi 2 septembre 2019

function does not evaluate on each occurance

I have a function that does not really evaluate each time.

I have a function that returns a normalisation within a range between -1 and 1. However, if the input is outside a defined range, it will return a larger number.

When i run it, it dont get why it doesent evaluate on each occurance, unless the function is within range

 x <- data.frame(c(0.01, -0.01, -0.105, 0.05))


funk <- function(x, mini, maxi) {

temp <-((((x-mini)/(maxi-mini))*2)-1)/100

ifelse( x<= mini, temp <- -10, temp)
ifelse( x>= maxi, temp <- 10, temp)

return(temp)}

x$funk <- funk(x[,1], -0.1, 0.1)

I was expecting x$funk = (0.001, -0.001, -10, 0.005)

Aucun commentaire:

Enregistrer un commentaire