ifelse()
On Tue, Feb 10, 2009 at 01:44:17PM -0800, kayj wrote:
I have a problem with ifelse(), I do not understand how it works.
X<-c(2,2,1,1,0,0) str(X)
num [1:6] 2 2 1 1 0 0
Y<-ifelse(X>0,1,0) Y
[1] 1 1 1 1 0 0
Can some one explain what is going on, I do not understand what ifelse is doing in this case. Can someone explain the output Y.
ifelse evaluates the condition given in its first argument and returns the value of the second argument for all cases found to be TRUE and the value of the third argument otherwise. As the first 4 elments of X fulfill your condition (X>0) the corresponding result for them is 1 and the rest 0. See ?ifelse for details. cu Philipp
Dr. Philipp Pagel Lehrstuhl f?r Genomorientierte Bioinformatik Technische Universit?t M?nchen Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel