function(x) { ifelse(abs(x) <= 1, 0, sign(x) * log10(abs(x))) }

function( x ) { ifelse ( abs ( x ) <= 1 , 0 , sign ( x ) * log10 ( abs ( x ))) }

if u know the solution for this please explain

Hi, and welcome.

For future reference, please read FAQ: What's a reproducible example (`reprex`) and how do I do one? and, if applicable FAQ: Homework Policy

First, you want to give the function a name, say

my_func <- function(x) {....}

Second, are you sure you mean sign?

sign(-2:3)
#> [1] -1 -1  0  1  1  1

Created on 2020-02-11 by the reprex package (v0.3.0)

If so, that's fine, and you'll get

my_func <- function( x ) { ifelse ( abs ( x ) <= 1 , 0 , sign ( x ) * log10 ( abs ( x ))) }

my_func(-10)
#> [1] -1
my_func(0)
#> [1] 0
my_func(10)
#> [1] 1

Created on 2020-02-11 by the reprex package (v0.3.0)

If you want sin instead of sign

my_func <- function( x ) { ifelse ( abs ( x ) <= 1 , 0 , sin ( x ) * log10 ( abs ( x ))) }

my_func(-10)
#> [1] 0.5440211
my_func(0)
#> [1] 0
my_func(10)
#> [1] -0.5440211

Created on 2020-02-11 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.