Skip to content
Prev 308676 / 398503 Next

creating a function using for if

Try this -- this uses the vectorization which you need to read up on
in the Intro to R:
+ {
+ N <- numeric(length(data))  # initialize to zero
+ indx <- data > c  # determine which data is greater than c
+ N[indx] <- (a * (data[indx] - c) ^ 0.5) + (b * (data[indx] - c))
+ N
+ }
[1]      0.00  77471.67 130418.05      0.00  44725.36      0.00
83680.00      0.00      0.00
[10]      0.00

        
On Mon, Oct 22, 2012 at 10:51 AM, Balqis <aehan3616 at gmail.com> wrote: