Re: [R] Multiplying each row of data.frame by a row in another data.frame

2022-04-09 Thread Avi Gross via R-help
Within standard R, it is common to take objects that are lists (as a data.frame is) apart and apply some function and recombine them. So using my example in an earlier message, and hoping this text-mode message is readable, try something like this to multiply each column of a data.frame by the

Re: [R] "apply" a function that takes two or more vectors as arguments, such as cor(x, y), over a "category" or "grouping variable" or "index"?

2022-04-09 Thread Kelly Thompson
Thanks. I have a clarification and a follow-up question. I should have asked this in the original post, and I should have provided a better example for the FUN argument, I apologize. For use in an example, here is a "silly" example of a function that requires arguments such as x and y to be "separ

Re: [R] Multiplying each row of data.frame by a row in another data.frame

2022-04-09 Thread Eric Berger
This looks like homework, which is not permitted on this list. But giving you the benefit of the doubt, here are two ways to do it > as.matrix(val_df) * matrix(rep(weights$value,5),ncol=3,byrow = TRUE) ABC DEF ONS [1,] 10 2 500 [2,] 20 4 500 [3,] 10 20 1000 [4,] 10 4 500 [5,]