I have seen this post (How to access the last value in a vector?) showing how to use the tail function. When I apply tail to a factor, it returns all the levels of the factor, including the last factor to appear. Example:
x = rep(1:4, 6)
y = rnorm(4*length(x), 0, 0.1)
d = data.frame(ERF=x, y)
d$ERF = factor(d$ERF)
a <- tail(d$ERF, n=1)
> a
[1] 4
Levels: 1 2 3 4
I just want to store the last factor as a variable (a). I can see that a[1] is 4 but:
> a[1]
[1] 4
Levels: 1 2 3 4
I looked at ?tail
but cant seem to figure it out. I know it must be simple I just need a nudge in the right direction. Thanks