[R] Text in a character vector to indicate "ifelse" argument

joe1985 johannes at dsr.life.ku.dk
Thu Jan 29 10:25:13 CET 2009


Hello

I have a data set that looks like this; 

> b2
          dato         chr                      status           PRRSvac
PRRSsanVac PRRSsanDk PRRSdk
33  2007-12-03 090432                    Rød SPF        
34  2007-02-09 090432              Rød SPF+sanDK        
35  2002-12-17 090432                 Rød SPF+DK        
36  2002-11-27 090432              Rød SPF+sanDK        
37  2002-07-23 090432                 Rød SPF+DK        
38  2001-08-23 090432                    Rød SPF        
39  2000-01-01 090432          SPF-X,  PRRS-neg.        
40  1999-05-01 090432           MS-X,  PRRS-neg.        
81  2001-08-23 022458                    Rød SPF        
82  1999-01-22 022458          SPF-X,  PRRS-neg.       
130 2008-10-16 080385 Rød SPF+Myc+Ap2+Nys+DK+Vac       
131 2003-03-18 080385     Rød SPF+Myc+Ap2+DK+Vac        
132 2002-11-01 080385         Rød SPF+Myc+DK+Vac        
133 2002-02-07 080385            Rød SPF+Myc+Vac        
134 2000-09-19 080385         MS-X,  PRRS-pos VAC       
135 1999-01-22 080385            MS-X,  PRRS-neg        
176 2008-10-28 013168 Rød SPF+Myc+Ap2+Nys+DK+Vac        
177 2003-05-23 013168     Rød SPF+Myc+Ap2+DK+Vac        
178 2002-11-01 013168         Rød SPF+Myc+DK+Vac        
179 2001-07-03 013168            Rød SPF+Myc+Vac        
180 2000-09-01 013168         MS-X,  PRRS-pos VAC      
181 2000-06-02 013168            MS-X,  PRRS-neg        
182 2000-04-03 013168     SKM-X,  +Ap2,  PRRS-neg       
183 1999-01-22 013168            MS-X,  PRRS-neg        

Where I have used;

b2$PRRSvac <- ifelse(b2$status=='PRRS-pos VAC' | b2$status=='Vac',1,0)
b2$PRRSdk <- ifelse(b2$status=='PRRS-pos DK' | b2$status=='DK',1,0)
b2$PRRSsanVac <- ifelse(b2$status=='sanVac',1,0)
b2$PRRSsanDk <- ifelse(b2$status=='sanDK',1,0)

to creat the last four variables, but it wont work!!! The variable status
has class "character". 

Can anyone help me?

-- 
View this message in context: http://www.nabble.com/Text-in-a-character-vector-to-indicate-%22ifelse%22-argument-tp21722983p21722983.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list