Hi. I saw this example and I cannot begin to figure out how it works. Can
anyone give me an idea on this?

n = 9e6
df = data.frame(values = rnorm(n),
                ID = rep(LETTERS[1:3], each = n/3),
                stringsAsFactors = FALSE)
> head(df)
      values ID
1 -0.7355823  A
2 -0.4729925  A
3 -0.7417259  A
4  1.7633367  A
5 -0.3006790  A
6  0.6785947  A


The idea is to replace all occurrences of A by    'Text for A'.

He does this:

translator_vector = c(A = 'Text for A',
                      B = 'Text for B',
                      C = 'Text for C')

and subset this vector using df$ID:

dum_vectorized = translator_vector[df$ID]

It works but I have no idea why.

Thank you.

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to