0

I am learning R. I am completely new in this language. So Im Very much confusing with labels and levels.

r2evans
  • 77,184
  • 4
  • 55
  • 96
  • 1
    maybe you are thinking of `factor(..., labels = )` but the function `labels` from base r is not useful for factors as it will simply give you `as.character(seq_along(object))` – rawr Feb 02 '21 at 17:54
  • 1
    When you turn a vector into a factor, levels are the (possible) unique values of this vector. Labels are the values assigned to the levels. Take school grades as an example. Levels could be > 90 %, 80-90 %, 70-80 %, 60-70%, < 60 % correct answers. In the US, the labels would then be A, B, C, D, F. – Roland Feb 02 '21 at 17:55
  • [Confusion between factor levels and factor labels](https://stackoverflow.com/questions/5869539/confusion-between-factor-levels-and-factor-labels); [Why is the terminology of labels and levels in factors so weird?](https://stackoverflow.com/questions/7128413/why-is-the-terminology-of-labels-and-levels-in-factors-so-weird) (easily found with the search `[r] factor levels labels` in SO, sort by votes) – Henrik Feb 02 '21 at 20:36

1 Answers1

0

You can assign a label to a variable to give the variable a readable and understandable name. Calculations are done with the variable name not with the label of the variable. The label for the variable los can be "Length of stay".

Levels are important with factor variables. Each value of a factor variable is a level. For example the factor variable eye_color can have the levels "blue", "brown" and "green". So a factor variable may have a label, but has always levels (at least one). Example: The factor variable eye_color may have the label "Eye Color" and has the above mentioned 3 levels ("blue", "brown", and "green).

TarJae
  • 8,026
  • 2
  • 8
  • 25