zoukankan      html  css  js  c++  java
  • R语言中提取多个连续值的累计的中间位点

    1、R实现

    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

    2、shell实现

    root@DESKTOP-1N42TVH:/home/test# ls
    a.txt
    root@DESKTOP-1N42TVH:/home/test# cat a.txt
    20
    50
    40
    60
    80
    root@DESKTOP-1N42TVH:/home/test# base=0
    root@DESKTOP-1N42TVH:/home/test# temp=0
    root@DESKTOP-1N42TVH:/home/test# for i in `cat a.txt`; do let temp=$base+$i*1/2,base=$base+$i;echo $temp>> result.txt; done
    root@DESKTOP-1N42TVH:/home/test# ls
    a.txt  result.txt
    root@DESKTOP-1N42TVH:/home/test# cat result.txt   ##查看结果
    10
    45
    90
    140
    210
  • 相关阅读:
    关于《哈利波特》书的购买方案
    你的灯亮着吗读后感三
    jmeter做接口测试
    jmeter的分布式部署
    JMeter的定时器
    我的功能测试用例是怎么写
    常见的功能测试检查点
    测试用例概论
    敏捷开发与迭代开发
    软件测试模型
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/15770474.html
Copyright © 2011-2022 走看看