[R] Creat new column based on condition

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sat Apr 22 10:04:50 CEST 2006


Peter Dalgaard <p.dalgaard at biostat.ku.dk> writes:

>  I think I'd go for something like
> 
>    V2 <- c(4, 6, 10)[factor(V1, levels=c(10, 20, 30))]

Come to think of it: 

   c(4, 6, 10)[match(V1, c(10, 20, 30))]

is more to the point.


-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list