Re: [R] Is there any concise way to write a one-to-one mapping?

2015-09-14 Thread Duncan Murdoch
On 14/09/2015 1:35 PM, jpm miao wrote: My code is: if(type=="none") type2<-"nc" if(type=="drift") type2<-"c" if(type=="trend") type2<-"ct" These are concise: type2 <- c(none = "nc", drift = "c", trend = "ct")[type] type2 <- switch(type, none = "nc", drift = "c", trend = "ct")

Re: [R] Is there any concise way to write a one-to-one mapping?

2015-09-14 Thread Jeff Newmiller
Assuming your data are in a data frame, make anorher data frame with the type and type2 columns and merge it with your original data frame. ?merge --- Jeff NewmillerThe . . Go Live..

[R] Is there any concise way to write a one-to-one mapping?

2015-09-14 Thread jpm miao
My code is: if(type=="none") type2<-"nc" if(type=="drift") type2<-"c" if(type=="trend") type2<-"ct" I am wondering if there's a concise way to write a mapping from type to type2, especially when the number of categories is high. Thanks! [[alternative HTML version deleted]]