r - Invalid For-Loop using Sequence in R
问题描述
I am beginner in R so when I tried to make a for loop by sequence it gave me the expected result for one vector but for the second one, it gave me the same value along the vector (It made only the first iteration )
moyenne<- c()
ecart<-c()
for(i in seq(1,length(vector1), by=nbsim)){
moyenne<-c(moyenne, mean(P_totale-GRAVE- ATTRITIONNEL-vector2[i:i+nbsim-1]+vector1[i:i+nbsim-1]))
#mean of the result
ecart<-c(ecart,sqrt(var(vector1[i:i+nbsim-1]-vector2[i:i+nbsim-1]-ATTRITIONNEL-GRAVE+P_totale)))
#standard deviation of the result
}
moyenne
ecart
vector1 and vector 2 have the same length which is equal to 90000, P_totale, GRAVE and ATTRITIONNEL are vectors with length=nbsim My problem was with the vector "ecart", I didn't know why it gave me the same value, could someone help me, please ?
解决方案
推荐阅读
- html - 动画汉堡切换按钮无法正常工作
- node.js - Laravel Mix: npm run dev 和 npm run watch error-> configuration.loader 应该是一个对象
- php - 在视图中使用 baseController 中的对象变量时出现错误
- kubernetes - 没有钩子的 kubernetes preStop 优雅关闭超时
- google-ads-api - 尝试为 Google Adwords (V201809) API 设置代理服务器
- java - 将图像加载到 Java 数据库时出错
- android - Android 崩溃 - kotlin.UninitializedPropertyAccessException MainActivity.getAdapterGallery
- facebook - Facebook Conversions API 警告缺少事件 ID?
- r - 如何在加载阶段禁用 UI 元素
- windows - Windows“开始”菜单启动文件夹中的自复制脚本