NB: Quite a beginner, so probably missing something obvious.
I am trying to write some generalizable code to do some factor-based analysis in R. I have a list of factors and their levels such that
$group
[1] "NR" "NV" "NT"
$device
[1] "X" "Y"
$width
[1] "fat" "nom"
$length
[1] "long" "nom"
I'm trying to write a loop to extract the individual levels of each factor in sequence (in the first case, "NR"), without using the name of the factor since that will change with different data sets.
I can get all the levels of a given factor by
factors[1]
or an individual level by
factors$group[1]
but how do I extract an individual level in a way that doesn't use the name of the factor? It can be done in a couple of steps, by for example
demo <- factors[[1]]
demo[1]
but that seems sloppy, since I don't actually need the variable demo to exist. Is there a neater way?