How to access the last value in a vector?

后端 未结 11 1282
栀梦
栀梦 2020-11-28 18:05

Suppose I have a vector that is nested in a dataframe one or two levels. Is there a quick and dirty way to access the last value, without using the length() fu

11条回答
  •  没有蜡笔的小新
    2020-11-28 18:10

    I have another method for finding the last element in a vector. Say the vector is a.

    > a<-c(1:100,555)
    > end(a)      #Gives indices of last and first positions
    [1] 101   1
    > a[end(a)[1]]   #Gives last element in a vector
    [1] 555
    

    There you go!

提交回复
热议问题