I want to multiply df by matrix. Df has 0 values, and the matrix has NA values (which is important). By multiplying 0 (in df) with the value (in mat), I get 0 and multiplying the value (in df) by NA (in mat), I get NA, which is true and perfectly normal for me. However, when I multiply 0 (df) with NA (mat), I get NA, which is probably true. But is there a way to get 0? Since I'm interested in these 0. Here are some sample data:
df0 <- data.frame(a=1, b=0, c=2, d=5, e=0)
mat0 <- matrix(c(NA,2,NA,4,NA),nrow=1, ncol=5)
df_mat0 <- df0 * mat0
My expected result (0 in e):
a b c d e
1 NA 0 NA 20 0
Ideas? Thanks
source
share