r - data.frame 中所有变量对的元素乘法之和
问题描述
除了简单地为下面的 data.framecrossprod
执行(.1*.3)+(.2*.4)
和输出之外,它们是否还有任何 BASE 功能?.11
注意:这是一个玩具示例,data.frame 可以有任意数量的列。
x = data.frame(a = c(.1, .2), b = c(.3, .4))
# Desired Output
(.1*.3)+(.2*.4) #= .11
crossprod(as.matrix(x))
# Current output
a b
a 0.05 0.11
b 0.11 0.25
解决方案
c(do.call("%*%", x))
[1] 0.11
甚至
x$a%*%x$b
推荐阅读
- html - 为什么我正在使用的两个视频相互重叠?
- python - python中的缩进错误,如何检查空格或制表符以避免错误?
- regex - 正则表达式:在文件中的任何位置查找没有不同目标的单词?
- python-3.x - 如何修复我的代码在列表中找不到关键字?
- syntax - 'up{}' 语法是什么意思?
- asp.net-core - 如何从 IGraphServiceClient 对象中获取用户?
- javascript - 如何在 for 循环内的 Promise 中设置状态
- swift - 将文件移动到我自己的应用程序中存在同名文件的目录时,是否可以使用 Finder 提供的警报?
- linux - 如何使用 rrdtool 命令获取 MIN MAX 使用的 nagios perf 数据?
- c - 带字符串的 Printf 不起作用(2 种方式:函数返回值和只是一个值)