‘apply’ on two different data frames at once in R

We can use mapply or Map

mapply(function(x, y) dnorm(df_data$CC[df_data$DY == x], y, 
       log = TRUE), df_model$DY, df_model$CC)

-output

#          [,1]       [,2]      [,3]
#[1,] -1.5031401 -2.7449464 -1.734319
#[2,] -0.9237629 -0.9243094 -1.115875
#[3,] -4.9848319 -1.1494313 -1.187122

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top