【问题标题】:Insert new value into a vector such that the first element is always the newly inserted one将新值插入向量中,使第一个元素始终是新插入的元素
【发布时间】:2020-02-10 02:08:45
【问题描述】:
example<-c(1,2,3)
to_be_inserted<-1

example<-append(example, to_be_inserted)

我得到的结果是c(1,2,3,1) 但是我想要c(1,1,2,3)

我怎样才能做到这一点?

【问题讨论】:

    标签: r vector append


    【解决方案1】:

    您可以使用追加功能。

    > append(1,example)
    [1] 1 1 2 3
    

    【讨论】:

      【解决方案2】:

      我们可以使用c 来连接向量。

      c(to_be_inserted, example)
      #[1] 1 1 2 3
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-09
        • 1970-01-01
        • 1970-01-01
        • 2010-12-02
        • 1970-01-01
        • 2013-04-02
        相关资源
        最近更新 更多