indicator function 1(•)

Hello,

I'm trying to create an indicator function 1(•) for my variable "demand", but I'm not sure if this is correct. I have tried it like this:

``````#for the indicator function 1(demand=0)
summary(as.numeric(demand==0))

#for the indicator function 1(demand>0)
summary(as.numeric(demand>0))
``````

Can anyone tell me if this is the right thing to do?

Thank you very much.

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

Unfortunately I could not install the reprex package. Hope it is also traceable with the minimal dataset and minimal runnable code:

``````df <- data.frame(
demand = c(0.24455661001999, 0.288511028213395, 0.000457341625207,
0.286052311527696, 0.22661840138977),
giniA = c(0.600622095598854, 0.611145511322019, 0.611145511322019,
0.609040828177386, 0.611145511322019)
)

#indicator function 1(.) for demand

summary(as.numeric(df\$demand<1))
sd(as.numeric(df\$demand<1))
summary(as.numeric(df\$demand==1))
sd(as.numeric(df\$demand==1))
summary(as.numeric(df\$demand>1))
sd(as.numeric(df\$demand>1))

#indicator function 1(.) for giniA

summary(as.numeric(df\$giniA>0))
sd(as.numeric(df\$giniA>0))
summary(as.numeric(df\$giniA==0))
sd(as.numeric(df\$giniA==0))
``````

Is it right to do this for the creation of an indicator function or is there another way?

Thank you so much for your help.

Sorry but I really don't understand what are you trying to accomplish with the code you are posting, as long as I know, an indicator function simply returns 1 or 0 depending on a defined treshold, like in this example.

``````library(dplyr)

df <- data.frame(
demand = c(0.24455661001999, 0.288511028213395, 0.000457341625207,
0.286052311527696, 0.22661840138977),
giniA = c(0.600622095598854, 0.611145511322019, 0.611145511322019,
0.609040828177386, 0.611145511322019)
)

df %>%
mutate(demand_indicator = if_else(demand > 0, 1, 0),
giniA_indicator = if_else(giniA > 0, 1, 0))
#>         demand     giniA demand_indicator giniA_indicator
#> 1 0.2445566100 0.6006221                1               1
#> 2 0.2885110282 0.6111455                1               1
#> 3 0.0004573416 0.6111455                1               1
#> 4 0.2860523115 0.6090408                1               1
#> 5 0.2266184014 0.6111455                1               1
``````

Created on 2019-08-09 by the reprex package (v0.3.0.9000)

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