[R] understanding the no-label concept

Ista Zahn istazahn at gmail.com
Mon Oct 20 19:31:44 CEST 2014


On Thu, Oct 16, 2014 at 3:19 PM,  <moonkid at posteo.org> wrote:
>> aa <- 1:5
>> names(aa) <- c("Eins", "Zwei", "Drei", "Vier", "Fünf")
>> aa
> Eins Zwei Drei Vier Fünf
>    1    2    3    4    5
>> table(aa)
> 1 2 3 4 5
> 1 1 1 1 1
>
> You see? It didn't work.

perhaps you want

table(names(aa))

Or maybe just

aa <- - c("Eins", "Zwei", "Drei", "Vier", "Fünf")
table(aa)

>
>> aa <- c(aa, 1, 2)
>> aa
> Eins Zwei Drei Vier Fünf
>    1    2    3    4    5    1    2

This does get more complicated if you want to add things by number.
But why not just


aa <- - c("Eins", "Zwei", "Drei", "Vier", "Fünf")
aa <- c(aa, "Eins", "Zwei")
table(aa)

?

>
> This is no solution for my case.
>
> But...
>
>> bb <- matrix(1:12, 3, 4, dimnames=list(letters[1:3], LETTERS[1:4]))

Not really sure what this is meant to demonstrate.

More generally there is no one-to-one mapping between the stata
concept of variable and value labels to concepts in R. First, there is
no equivalent of Stata variable labels. There is ?comment but it
doesn't survive subsetting. The role that value labels play in Stata
are covered variously in R by 1) just using character strings to store
the information that you would typically put in a stata value label,
b) naming your variable, or c) using factors. Personally I usually
find option 1) more convenient.

Best,
Ista

>
> Nice. But look dam complex for a simple task. I see I have to change a
> lot of the concepts in my mind and my workflows.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list