[R] Questions on formula in princomp

Sasha Pustota popgen at gmail.com
Sat Apr 15 06:07:33 CEST 2006


jim holtman <jholtman at gmail.com> wrote:
> does this explain it?
>
> > groups <- factor(c(rep("Z",5),rep("X",5),rep("Y",5)))
> >
> > groups
>  [1] Z Z Z Z Z X X X X X Y Y Y Y Y
> Levels: X Y Z
> > as.integer(groups)
>
>  [1] 3 3 3 3 3 1 1 1 1 1 2 2 2 2 2
>  > c(1,2,3)[groups]
>  [1] 3 3 3 3 3 1 1 1 1 1 2 2 2 2 2

I did notice the lexicographical ordering of Z,X,Y. I don't understand
the meaning of c(1,2,3) "subscription" by a factor. I understand
subscription by an integer, or by a single item as in associative
arrays. Or does "[]" have a different meaning here?




More information about the R-help mailing list