[R] Odp: repeating categorical variable codes
Petr PIKAL
petr.pikal at precheza.cz
Wed Oct 5 15:44:09 CEST 2011
Hi
>
> I would appreciate help in knowing how to repeat categorical variable
code
> given in column=A, by the number in a matching column=B.
> For example, I have a categorical variable code attributed to a
household=A
> and want to replicate the code for all member of the household, as given
in
> column=B. I would like to have one sequence of categorical variable
codes
> for individuals in column C. I have ~9000 values in A and my C will be
> ~52000.
>
> E.g
> (A) (B) (C)
> 1 1 1
> 2 2 2
> 1 1 2
> 2 3 1
> 2
> 2
> 2
>
> Any ideas would be gratefully accepted by a novice R user.
I am not sure if I understand your problem but does rep(A, B)
give you what you want?
rep(letters[1:3], 1:3)
[1] "a" "b" "b" "c" "c" "c"
Regards
Petr
>
> Ric
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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