Tom Willems
2008-Sep-16 14:18 UTC
[R] help with SQL, how can i use functions in sql (pkg :sqldf)
Een ingesloten tekst met niet-gespecificeerde tekenset is gescrubt ... Naam: niet beschikbaar URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080916/2d0f3a45/attachment.pl>
Gabor Grothendieck
2008-Sep-16 14:23 UTC
[R] help with SQL, how can i use functions in sql (pkg :sqldf)
sqldf also works with MySQL (although its been less tested with that) and MySQL does support a wider range of functions than sqlite: http://dev.mysql.com/doc/refman/5.0/en/func-op-summary-ref.html On Tue, Sep 16, 2008 at 10:18 AM, Tom Willems <Tom.Willems at var.fgov.be> wrote:> Dear R ussers , > > I was trying to summaryse data with sql, from the sqldf pkg. > > it seemed like a promessing solution, yet all i can do in this is > calculate " avg" "count " and "sum". > > where i d like to use confidence intervals and standard deviation as wel. > > now i was trying to find a solution my self , but the closest i got was " > sqlite3_create_function16" > explained on > http://www.sqlite.org/c3ref/create_function.html > sadely i don't understand much of the explanation. > > Now i hoped sombody could give me an other SQL solution for this. > > the function i hoped to use is this one. > >> mean.CI <- > function (X,na.rm=T) > { names(X)<-NULL > if (is.vector(X)) {nn <- length(X)} > else {nn <- nrow(X)} > NAs <- sum(is.na(X)) > n <- nn-NAs > if (na.rm) > avg <- mean(X,na.rm=T) > Sd <- sd(X,na.rm=T) > Var <- var(X,na.rm=T) > if (is.matrix(X)) { > apply(X, 2, sd, na.rm = T) } > else if (is.vector(X)) { > confin <-qt(0.975,df=n-1)*(sd(X, na.rm = T)/sqrt(n))} > else if (is.data.frame(X)){ > confin <-qt(0.975,df=n-1)*((sapply(X, sd, na.rm = T))/sqrt(n))} > else {confin <- qt(0.975,df=n-1)*(sd(as.vector(X), na.rm > T))/sqrt(n)} > out <-round (c( avg-confin ,avg+confin) ,digits=3) > out > } > > > kind regards, > Tom > > > Disclaimer: click here > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >