r - 什么包包含 R 中的 '%<>%' 运算符
问题描述
https://scholar.princeton.edu/sites/default/files/bstewart/files/srg_crossval.pdf
与这些幻灯片一起,代码使用 '%<>%' 运算符。
有谁知道这是什么或它用于什么包装?
代码读取
# Function to divide data into folds randomly
fold <- function(data, k) {
data <- data[sample(nrow(data)),] # Shuffle data
data %<>% mutate(fold = cut(seq(1:nrow(data)), breaks = k, labels=FALSE))
return(data)
}
# Function to cross-validate data on given model (curried)
cv.predict.logit <- function(data, dv, model.fx, k) {
data %<>% fold(k) # Fold data
aucs <- c()
for(i in 1:k) {
# Divide data into train and test sets
train <- data %>% filter(fold != i)
test <- data %>% filter(fold == i)
# Estimate model on training data
mx <- model.fx(data=train)
# Predict on test data and calculate AUC
preds <- predict(mx, newdata=test, type="response")
AUC <- somers2(preds, test[[dv]])[1]
aucs[i] <- AUC
}
return(mean(aucs, na.rm=TRUE)) # Yield mean AUC
}
# Function to rerun CV results n times and average AUCs
crossval <- function(data, dv, model.fx, k, n) {
aucs <- replicate(n, cv.predict.logit(data, dv, model.fx, k))
return(aucs)
}
解决方案
这是包中的一个分配管道magrittr
:
将对象转发到函数或调用表达式中,并使用结果值更新 lhs 对象。
推荐阅读
- javascript - 如何根据 Book id 对用户进行排序?
- android - 使用 FLAG_ACTIVITY_SINGLE_TOP 缓慢打开已打开的活动
- reactjs - Axios 使用 Reactjs 每 60 秒自动刷新一次
- python - ValueError:无法为具有形状“(?,2500)”的张量“Placeholder_34:0”提供形状(24500、50、50、1)的值
- makefile - 基于目标的 Makefile 环境
- powershell - Chrome 安装错误:“Egads!安装失败”
- python - 熊猫与独特的匹配合并
- php - 未找到特征“Laravelista\Comments\Comments\Traits\Comments”
- networking - 如何在 2 个 Kubernetes 集群之间配置 VPN 连接
- python - 如何修复列表索引超出范围错误?