[R] conditional value assignment
Frank Tamborello
franklin.tamborello at uth.tmc.edu
Mon Feb 14 10:02:08 CET 2011
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
More information about the R-help
mailing list