其他分享
首页 > 其他分享> > R语言中提取多个连续值的累计的中间位点

R语言中提取多个连续值的累计的中间位点

作者:互联网

1、

test <- c(20,50,40,60,80)  ## 测试数据
coordinate <- vector()
base <- 0
temp <- 0
for (i in 1:length(test)) {
  temp <- base + 0.5 * test[i]
  coordinate <- c(coordinate,temp)
  base <- base + test[i]
}
coordinate
> test <- c(20,50,40,60,80)  ## 测试数据
> coordinate <- vector()     ## 创建空向量
> base <- 0
> temp <- 0
> for (i in 1:length(test)) {
+   temp <- base + 0.5 * test[i]  ##在基础数基础上增加对应数的一半
+   coordinate <- c(coordinate,temp)
+   base <- base + test[i]  ## 基础数递增
+ }
> coordinate   ## 结果
[1]  10  45  90 140 210

 

标签:提取,语言,temp,##,210,45,coordinate,test,位点
来源: https://www.cnblogs.com/liujiaxin2018/p/15770474.html