[R] Two last questions: about output

Gabor Grothendieck ggrothendieck at gmail.com
Thu Oct 16 03:57:22 CEST 2008


Put the data in an R data frame and use dbWriteTable() to
write it to your MySQL database directly.

On Wed, Oct 15, 2008 at 9:34 PM, Ted Byers <r.ted.byers at gmail.com> wrote:
>
> Here is my little scriptlet:
>
> optdata =
> read.csv("K:\\MerchantData\\RiskModel\\AutomatedRiskModel\\soptions.dat",
> header = FALSE, na.strings="")
> attach(optdata)
> library(MASS)
> setwd("K:\\MerchantData\\RiskModel\\AutomatedRiskModel")
> for (i in 1:length(V4) ) {
>   x = read.csv(as.character(V4[[i]]), header = FALSE, na.strings="");
>   y = x[,1];
>   fp = fitdistr(y,"exponential");
>   print(c(V1[[i]],V2[[i]],V3[[i]],fp$estimate,fp$sd))
> }
>
>
> And here are the first few lines of output:
>
>                                               rate         rate
> 2.510000e+02 2.008000e+03 1.800000e+01 6.869301e-02 6.462095e-03
>                                               rate         rate
> 2.510000e+02 2.008000e+03 1.900000e+01 5.958023e-02 4.491029e-03
>                                               rate         rate
> 2.510000e+02 2.008000e+03 2.000000e+01 8.631714e-02 7.428996e-03
>                                               rate         rate
> 2.510000e+02 2.008000e+03 2.200000e+01 1.261538e-01 1.137491e-02
>                                               rate         rate
> 2.510000e+02 2.008000e+03 2.300000e+01 1.339523e-01 1.332875e-02
>                                               rate         rate
> 2.510000e+02 2.008000e+03 2.400000e+01 8.916084e-02 1.248501e-02
>
> There are only two things wrong, here.
>
> 1) the first three columns are integers, and are output variously as
> integers, floating point numbers and, as shown here, in scientific notation.
> 2) this output isn't going to a file or to my DB.  This second issue isn't
> much of a problem, as I think I know now how to deal with it.
>
> This output data is, in one sense, perfectly organized, and there is a table
> with a nearly identical structure (these five columns, plus one to hold the
> date on which the analysis is performed (and of course, therefore, it has a
> default value of the current timestamp  - handled in MySQL).  If I can get
> the data written to a CSV file, with the first three columns provided as
> integers, I can use the DB's bulk load utility to get the data into the DB,
> and this may be faster than having this scriptlet connecting directly to the
> DB to insert the data (unless the DBI has a function for a bulk load that
> helps here).
>
> Any idea how best to handle my formatting problem here?
>
> Thanks
>
> Ted
> --
> View this message in context: http://www.nabble.com/Two-last-questions%3A-about-output-tp20005519p20005519.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list