I am writing code. But instead of counting the sum of all the values that came up, it simply gives the last suitable value. How to save all suitable values?
filtered.sum <- function(x){ x[is.na(x)] <- 0 d <- 0 for (i in 1:length(x)) { if (x[i]>0){ s <- x[i] } } d <- d+s return(d) }