Re: [R] need help calculating the indicator function

2021-01-30 Thread Rui Barradas
Hello, Please cc the list, R-Help is threaded and your doubt and answers might be of interest to others. With a vector Y, you want 0 in all Y != l and 1 in all Y == l? n_l <- function(Y, l) as.integer(Y == l) Hope this helps, Rui Barradas Às 11:26 de 30/01/21, Ablaye Ngalaba escreveu: H

Re: [R] need help calculating the indicator function

2021-01-29 Thread Rui Barradas
Hello, Maybe this? n_l <- function(Y, l, na.rm = FALSE) sum(Y == l, na.rm = na.rm) set.seed(2020) q <- 6 y <- sample(q, 10, TRUE) l <- 4 n_l(y, l) #[1] 3 Hope this helps, Rui Barradas Às 14:27 de 29/01/21, Ablaye Ngalaba escreveu: Hello, please, I need to calculate the indicator function

Re: [R] need help calculating the indicator function

2021-01-29 Thread David Winsemius
Perhaps (in R): n_i <- cumsum( Y==l ) You should read further regarding R's logical class, and operators that work on it, and how it is coerced. -- David On 1/29/21 6:27 AM, Ablaye Ngalaba wrote: > Hello, > please, I need to calculate the indicator function as I underlined in my > attached

Re: [R] need help calculating the indicator function

2021-01-29 Thread Bert Gunter
Is this a homework problem? The posting guide linked below explicitly says: "*Basic statistics and classroom homework:* R-help is not intended for these." Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Brea