generate column values with multiple conditions in R
I have a dataframe z and I want to create the new column based on the values of two old columns of z . Following is the process: >z<-cbind(x=1:10,y=11:20,t=21:30) > z<-as.data.frame(z) >z x y t 1 1 11 21 2 2 12 22 3 3 13 23 4 4 14 24 5 5 15 25 6 6 16 26 7 7 17 27 8 8 18 28 9 9 19 29 10 10 20 30 # generate the column q which is equal to the values of column t times 4 if x=3 and for other values of x , it is equal to the values of column t . for (i in 1:nrow(z)){ z$q[i]=if (z$x[i]==4) 4*z$t[i] else z$t[i]} But, my problem is that I want to apply multiple conditions: For example, I want to get