I have a dataset with 17 variables, all of them integer/num. For a better descriptive analysis I created this user defined function :
sum <- function(x)
{
na.len<-sum(is.na(x))
mean<-mean(x,na.rm=T)
sd<-sd(x,na.rm=T)
min<-min(x,na.rm=T)
q1<-quantile(x,0.25,na.rm=T)
q3<-quantile(x,0.75,na.rm=T)
max<-max(x,na.rm=T)
UC1=mean+3*sd
LC1=mean-3*sd
UC2=quantile(x,0.99,na.rm=T)
LC2=quantile(x,0.01,na.rm=T)
iqr=IQR(x,na.rm=T)
UC3=q3+1.5*iqr
LC3=q1-1.5*iqr
ot<-max>UC1 | min<LC1 | max>UC2 | min<LC2 | max>UC3 | min<LC3
x[x>max]<-max
x[x<min]<-min
out_exist <- ifelse(noofNA > 0, "outlier_exists", "")
return(c(noofNA=na.len,mean=mean,std=sd,min=min,q1=q1,q3=q3,max=max,outlier=ot, out_exists= out_exist))
}
When I use this function on my dataset using :
apply(df, 2, sum)
I get following error :
Error: evaluation nested too deeply: infinite recursion / options(expressions=)? Error during wrapup: evaluation nested too deeply: infinite recursion / options(expressions=)?
I am trying to understand what's the issue but all in vain, please help!
sum, then inside it, you call the functionsumto perform summation. Change the name of your function. - user3710546mean<-mean(x,na.rm=T), instead of naming resultmeantry using something like this:meanResult <- mean(x, na.rm = TRUE)- pogibassum <- function(x){ sum(x) }; sum(1).Error: evaluation nested too deeply: infinite recursion / options(expressions=)?- user3710546