自动化乘法过程

Automating a multiplication process

我目前正在将 .6 乘以 sqrt() vi 下面我的 data 中每对唯一的元素。

我是 R 的新手,但想知道是否有办法自动执行此过程?

m = "
  study treatment focus_cat        yi        vi
1     1         1     type2 1.7581030 0.3947423
2     1         2     type1 1.9324494 0.8075765
3     1         3     type1 0.1225808 0.5933262
"
data <- read.table(text = m,h=T)

# How to automate the following and not repeat 3 lines of code:

.6 * sqrt(0.3947423*0.8075765)
.6 * sqrt(0.3947423*0.5933262)
.6 * sqrt(0.8075765*0.5933262)

您可以使用 combn 之类的(感谢 @r2evans 帮助简化了我的第一种方法!)

.6 * sqrt(combn(data$vi, 2, prod))
#[1] 0.3387661 0.2903721 0.4153267