[R] factor failure

David Winsemius dwinsemius at comcast.net
Fri Aug 13 03:25:05 CEST 2010


On Aug 12, 2010, at 9:00 PM, elaine kuo wrote:

> Dear list,
>
>
> factor function was tried but failed.
> Pls kindly help and thank you.
>
> E.
>
>
> code
>
> rm(list=ls())
> library(faraway)
> data (pima)
>
> pima$test < - factor (pima$test)

There is a space between your "<" and your "-". R is interppreting  
that as "make a numerical comparison between pima$test on the lhs and  
minus factor(pima$test) on the rhs and quite sensibly saying you have  
given it a nonsensical task.

 > pima$test <- factor (pima$test)
 > str(pima$test)
  Factor w/ 2 levels "0","1": 2 1 2 1 2 1 2 1 2 2 ...
'

>  [1] NA NA NA NA NA NA


-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list