
Greetings R Community,
 
I am working with the ifelse function and it is returning something unexpected.  In the code the line with the MODE1 assignment the output is a vector [1] 4 5 6  but when I put the MODE1 object into the ifelse function [R}'s output for MODE1 is the first number from the string (4).  Why is this?  Given the supplied vector of x I would assume both the MODE1 and ifelse() lines to return the same result.  I would like the ifelse to return the entire vector [1] 4 5 6 as in the previous line.
 
OS: Win7
R version 2.14 beta


#=======================================================================
#                                        Beginning of code
#=======================================================================
x<-c(2,3,4,4,5,5,6,6,8,10)
  
df<-as.data.frame(table(x))       
df<-df[order(df$Freq),]         
m<-max(df$Freq)        
(MODE1<-as.vector(as.numeric(as.character(subset(df,Freq==m)[,1]))))
ifelse(sum(df$Freq)/length(df$Freq)==1,warning("No Mode: Frequency of all values is 1", call. = FALSE),MODE1)
#=======================================================================
#                                             End of code
#=======================================================================
 
                                                R Console Output
> (MODE1<-as.vector(as.numeric(as.character(subset(df,Freq==m)[,1]))))
[1] 4 5 6
> ifelse(sum(df$Freq)/length(df$Freq)==1,warning("No Mode: Frequency of all values is 1", call. = FALSE),MODE1)
[1] 4
 
Thank you in advance,
Tyler 		 	   		  
	[[alternative HTML version deleted]]

