Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
诸如A%*%B需要使用 将 data.frame 转换为矩阵的矩阵计算as.matrix(),但这种方式很麻烦。有没有更方便的方法来做这些事情?
A%*%B
as.matrix()
如果您反对只是as.matrix在使用之前必须将数据框包装起来,%*%那么您可以制作自己的二进制函数来为您进行包装
as.matrix
%*%
`%*df%` <- function(x, y){as.matrix(x) %*% as.matrix(y)} x <- data.frame(a = 1:2, b = 3:4) x %*df% x # a b #[1,] 7 15 #[2,] 10 22