r - 如何在 R 中使用更改的数据名称进行循环
问题描述
我想像这样在 R 中创建一个循环函数:
threshold_month = 3
dta_3 <- dta_fin %>%
filter(month < threshold_month)
threshold_month = 6
dta_6 <- dta_fin %>%
filter(month < threshold_month)
threshold_month = 9
dta_9 <- dta_fin %>%
filter(month < threshold_month)
如何使用阈值 3、6 和 9.. 制作循环功能?
解决方案
你可以试试这个:
for (threshold_month in c(3, 6, 9)) {
assign(paste0("dta_", threshold_month), filter(dta_fin, month < threshold_month))
}
推荐阅读
- mysql - 三张表的联合和左连接
- android - How to dynamically delete a view added with addView()
- azure-data-factory - Azure Datafactory ~ 获取容器中的最新文件
- python - 计算字符串中连续字母的数量,然后根据它们的频率排序
- sql - SQL Group By并从列表中返回对
- networking - 在同一路由器上使用单独的网络会提高性能吗?
- c# - SonarQube 漏洞
- amazon-web-services - 如何在 AWS IAM 策略中引用 StringOutput
- pandas - 使用 if 条件在不同数据帧上的列之间查找(熊猫)
- r - R中的SVM结果含义