Hello House,
Good day.
Please I have problem with the short code below and needs advice/direction accordingly. I have an input data (X) ranging from 2 to 40 at 2.5 interval. The length of X and Z datasets are 16. I am writing a conditional statement such that: for i = 1, Z[i] > 0, X =X[i] and for Z[i] = 0, X = 0.. Please note that i =1:16. The values of X and Z are found below:
X = seq(2, 40, 2.5)
Z = c(2, 1, 0, 4, 1, 1, 3, 0, 8, 1, 21, 0, 10, 0, 1, 5)
X <- matrix(X, nrow = length(X), byrow = TRUE)
Z <- matrix(Z, nrow = length(Z), byrow = TRUE)
head(X)
head(Z)
length(X)
length(Z)
d = NULL
df = NULL
for (i in 1:length(X)){
p = X[i]
r = Z[i]
p
r
temporary_function <- function(r) {
if (r > 0){
(p)
}
else {
(0)
}
}
}
mapply(FUN = temporary_function, X)