Skip to content
Prev 299011 / 398506 Next

Is it possible to remove this loop? [SEC=UNCLASSIFIED]

On Jul 3, 2012, at 5:08 AM, Jim Lemon wrote:

            
One more. Similar to Petr's, but perhaps a bit more accessible to a  
new R user:

a1$h2 <- as.numeric(a1$h1=="H")

I wasn't sure whether NA's would be handled in the same manner by  
these two methods so I tested:

 > ifelse( factor(c("H", "h", NA))=="H", 1, 0)
[1]  1  0 NA
 > as.numeric( factor(c("H", "h", NA))=="H")
[1]  1  0 NA