It's a vector of NA
, if the factor was not a displayed numeric.
df <- data.frame(cutoff = letters[1:26])
as.numeric(levels(df[,"cutoff"]))[df[,"cutoff"]]
# [1] NA NA NA NA NA NA NA NA NA NA NA NA ...
# Warning message:
# NAs introduced by coercion
Let's break it down, this shows you the levels of the factor, returning a character string:
levels(df[,"cutoff"])
# [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" ...
This tries to convert a character string to numeric (which it can't, and therefore returns NA
)
as.numeric(levels(df[,"cutoff"]))
# [1] NA NA NA NA NA NA NA NA NA NA NA NA NA ...
# Warning message:
# NAs introduced by coercion
Now, adding the last element [df[,"cutoff"]]
, all this does is subset the result by the factor
df[,"cutoff"]
, but since every element is NA, you wouldn't see any difference. In practice this would likely change the order of the result in unexpected (read: useless) ways.
as.numeric(levels(df[,"cutoff"]))[df[,"cutoff"]]
# [1] NA NA NA NA NA NA NA NA NA NA NA NA NA ...
# Warning message:
# NAs introduced by coercion