Dear R-Help, I am trying to compute a new variable, let's call it "target cannon orientation (tco)" based conditionally on old variables, "TargetColor," "CannonOriB," and "CannonOriR." For every case in the data set, if TargetColor is "B" then I want tco to equal the value for that case of CannonOirB, else CannonOriR. I've tried writing for loops and functions that I can feed to sapply. I suspect there must be a simple solution but I cannot seem to get either incantation to perform the assignment. What would be a good way to do this?
Example data: "TargetColor.1.18." "CannonOriB.1.18." "CannonOriR.1.18." "B" 5 3 "R" 5 3 Example assignment of tco "tco" 5 3 Thanks much! Frank Tamborello, PhD W. M. Keck Postdoctoral Fellow School of Biomedical Informatics University of Texas Health Science Center, Houston https://xfiles.uth.tmc.edu/Users/ftamborello/public/index.html ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.