[R] Question on Counting Factors - PS

S Ellison S.Ellison at LGCGroup.com
Wed Apr 11 16:14:59 CEST 2012


 

> -----Original Message-----
> This would do it in your example:
> 
> > levels(animals$V1) <- c("cat","tiger","dog","fish")
> > table(animals)
> 
> cat    tiger    dog     fish
>   2         2        0        0

But be very wary of
levels(animals$V2)<- c("cat","tiger","dog","fish")
table(animals$V2)

  cat tiger   dog  fish 
    2     2     0     0           # !!

levels overwrites factor levels... factor(x, levels = ...) doesn't.

S*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-help mailing list