Dear all, Does anyone have a suggestion on how to make this code more efficient? I have a large data frame that I want to merge with another data frame b.art.temp<- b.art[, c("BalteSFyndID", "RUBINKOD")] I first add an indicator column for each RUBINKOD: b.art.temp$anas.hel<- ifelse(b.art.temp$RUBINKOD=="ANAS.HEL", 1, 0) b.art.temp$ant.pulv<- ifelse(b.art.temp$RUBINKOD=="ANT.PULV", 1, 0) b.art.temp$anti.cur<- ifelse(b.art.temp$RUBINKOD=="ANTI.CUR", 1, 0) ... # and then merge b.substart<- merge(b.subst, b.art.temp[b.art.temp$anas.hel == 1, c("BalteSFyndID", "anas.hel")], by="BalteSFyndID", all.x=T) b.substart<- merge(b.substart, b.art.temp[b.art.temp$ant.pulv == 1, c("BalteSFyndID", "ant.pulv")], by="BalteSFyndID", all.x=T) b.substart<- merge(b.substart, b.art.temp[b.art.temp$anti.cur == 1, c("BalteSFyndID", "anti.cur")], by="BalteSFyndID", all.x=T) ... But there are many levels of RUBINKOD nlevels(b.art.temp$RUBINKOD) [1] 61 and I therefore wonder if there is any quicker way of doing it than repeating the abouve lines 58 more times Thanks in advance! Sincerely, Tord ----------------------------------------------------------------------- Tord Sn?ll Avd. f v?xtekologi, Evolutionsbiologiskt centrum, Uppsala universitet Dept. of Plant Ecology, Evolutionary Biology Centre, Uppsala University Villav?gen 14 SE-752 36 Uppsala, Sweden Tel: 018-471 28 82 (int +46 18 471 28 82) (work) Tel: 018-25 71 33 (int +46 18 25 71 33) (home) Fax: 018-55 34 19 (int +46 18 55 34 19) (work) E-mail: Tord.Snall at ebc.uu.se Check this: http://www.vaxtbio.uu.se/resfold/snall.htm! ------------------------------------------------------------------------