Dear all, I would like to do sample statistics, e.g. mean, median from very large dataset. This is part of commands I use routinely with several dataset so I would like to make it into function. The simplified examples are
Test<-data.frame(A=c('a','b','c','a','b','c'),B=c(1,2,3,4,5,6)) #Create function (This one work) GetAvg<-function(Input,Bygroup){ AVG<-fn$sqldf("select A, avg(B) as Average, median(B) as Median from Test group by $Bygroup") return(AVG) } Result<-GetAvg(Test,'A') #Create function (This one does not work) GetAvg<-function(Input,Bygroup){ AVG<-fn$sqldf("select A, avg(B) as Average, median(B) as Median from $Input group by $Bygroup") return(AVG) } Result<-GetAvg(Test,'A') The only difference is with $Input. How can I refer to this variable in sqldf. Thank you Best Regards, Suphajak Ngamlak Equity and Derivatives Trading Phatra Securities Public Company Limited Tel: +662-305-9179 Email: supha...@phatrasecurities.com [[alternative HTML version deleted]] ______________________________________________ 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.