Given something like ... x <- c(3,2,4,3,5,4,3,2,4,5) y <- c("A","B","B","A","A","A","A","B","A","B") xy <- data.frame(x,y) xy$w <- ifelse(xy$y=="A",xy$w[,x]*10,xy$w[,x]*15 ) want to see x y w 1 3 A 30 2 2 B 30 3 4 B 60 4 3 A 30 5 5 A 50 6 4 A 40 7 3 A 30 8 2 B 30 9 4 A 40 10 5 B 75 but I get NA's Jeff