Dear All: I need to create new variables based on the old data set: old data: =================== type x y 0 3 4 0 2 2 0 4 55 0 3 4 1 2 3 1 11 22 1 2 33 0 34 11 1 2 6 0 35 77 1 64 8 0 32 12 0 12 40 0 67 30 0 3 43 1 4 23 1 2 15 1 5 51 0 8 6 0 9 23 1 56 16 1 43 27 1 21 17 0 12 27 0 34 47
datatest<-read.table(file="F:\\00 - Spring 2012\\STA 591\\notes\\Module 2 - Linear Regression and Correlation\\Zar chapters 17-20\\olddata.txt",head=TRUE) ##### datatest datatest1<-data.frame(type =datatest[,1], x = datatest[,2], y = datatest[,3]) ##### datatest1 I want to get: =============== Create a new variable z as follows: if type =0 then z=1 and if type = 1 then z=0 then create one more variable called xz = x*z new data should look like this one =============================== type x y z xz 0 3 4 1 3 0 2 2 1 2 0 4 55 1 4 0 3 4 1 3 1 2 3 0 0 1 11 22 0 0 1 2 33 0 0 0 34 11 1 34 1 2 6 0 0 0 35 77 1 35 1 64 8 0 0 0 32 12 1 32 0 12 40 1 12 0 67 30 1 67 0 3 43 1 3 1 4 23 0 0 1 2 15 0 0 1 5 51 0 0 0 8 6 1 8 0 9 23 1 9 1 56 16 0 0 1 43 27 0 0 1 21 17 0 0 0 12 27 1 12 0 34 47 1 34 Thank you very much abou ========================== AbouEl-Makarim Aboueissa, Ph.D. Associate Professor of Statistics Graduate Program Coordinator Department of Mathematics & Statistics University of Southern Maine 96 Falmouth Street P.O. Box 9300 Portland, ME 04104-9300 USA Tel: (207) 228-8389 Fax: (207) 780-5607 Email: [email protected] [email protected] Office: 301C Payson Smith [[alternative HTML version deleted]] _______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-teaching
