Can someone explain why levels () shows three levels of factors, while you can see that a vector has only two?
> str(walk.df)
'data.frame': 10 obs. of 4 variables:
$ walker : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 2 2 2 2 2
> walk.df$walker
[1] 1 1 1 1 1 2 2 2 2 2
Levels: 1 2 3
I would like to extract a vector of levels, and I thought it was the right way, but, as you can see, there are three sneaks out there that messed up my function.
> as.numeric(levels(walk.df$walker))
[1] 1 2 3
source
share