I have a factor instrumentF
:
> instrumentF
[1] Guitar Drums Cello Harp
Levels: Cello Drums Guitar Harp
Let's say I extract one level of this factor using []
.
> level2 = instrumentF[1]
> level2
[1] Guitar
Levels: Cello Drums Guitar Harp
How I can get the factor label Guitar
from the factor object level2
?
level2$level
doesn't seem to work:
> Error in level2$level : $ operator is invalid for atomic vectors
Convert to character, see this example:
See relevant post: Convert data.frame columns from factors to characters
Or subset the level: