Export R object table to excel -


i searching way export table-like r objects excel/csv. example gains table, in r saved object. usual write.table function doesn't allow me convert object csv. although object table...:

gains(actual, predicted, groups=10,optimal=false,percents=false)->gains_test2

> dput(head(gains_test2))  structure(list(depth = c(10, 20, 30, 40, 50, 60, 70, 80, 90,  100), obs = c(146l, 147l, 147l, 147l, 147l, 146l, 147l, 147l,  147l, 147l), cume.obs = c(146l, 293l, 440l, 587l, 734l, 880l,  1027l, 1174l, 1321l, 1468l), mean.resp = c(0.0116469582940705,  0.0125322442801302, 0.0142252481339337, 0.0106531565074638, 0.0130847548479835,  0.0106034244135535, 0.00455378455081303, 0.0061834241946857,  0.00989105136990672, 0.00841145735618072), cume.mean.resp = c(0.0116469582940705,  0.012091112014039, 0.0128041074904584, 0.0122654536667783, 0.012429537145848,  0.0121265684425355, 0.0110426354025324, 0.0104341992461836, 0.010373758112336,  0.0101772606932932), cume.pct.of.total = c(0.113817337305101,  0.237124763149948, 0.377090015198269, 0.481908695451763, 0.610652390679108,  0.714272022740551, 0.759077680710614, 0.819917710900762, 0.917237876073098,  1)), .names = c("depth", "obs", "cume.obs", "mean.resp", "cume.mean.resp",  "cume.pct.of.total"))    > print(gains_test2) depth                           cume    cume pct                     mean of          cume     mean      mean    of total    lift   cume     model file    n      n      resp      resp      resp     index   lift     score -------------------------------------------------------------------------  10   146    146      0.01      0.01     11.38 %     114    114      0.02   20   147    293      0.01      0.01     23.71 %     123    119      0.01   30   147    440      0.01      0.01     37.71 %     140    126      0.01   40   147    587      0.01      0.01     48.19 %     105    121      0.01   50   147    734      0.01      0.01     61.07 %     129    122      0.01   60   146    880      0.01      0.01     71.43 %     104    119      0.01   70   147   1027      0.00      0.01     75.91 %      45    109      0.01   80   147   1174      0.01      0.01     81.99 %      61    103      0.01   90   147   1321      0.01      0.01     91.72 %      97    102      0.01  100   147   1468      0.01      0.01    100.00 %      83    100      0.01   > as.data.frame(gains_test2) error in as.data.frame.default(gains_test2) :    cannot coerce class '"gains"' data.frame 

any idea? thanks!

========================================================================

it's not dataframe, pretty easy turn one.

dat <- as.data.frame(structure(list(depth = c(10, 20, 30, 40, 50, 60, 70, 80, 90,  100), obs = c(146l, 147l, 147l, 147l, 147l, 146l, 147l, 147l,  147l, 147l), cume.obs = c(146l, 293l, 440l, 587l, 734l, 880l,  1027l, 1174l, 1321l, 1468l), mean.resp = c(0.0116469582940705,  0.0125322442801302, 0.0142252481339337, 0.0106531565074638, 0.0130847548479835,  0.0106034244135535, 0.00455378455081303, 0.0061834241946857,  0.00989105136990672, 0.00841145735618072), cume.mean.resp = c(0.0116469582940705,  0.012091112014039, 0.0128041074904584, 0.0122654536667783, 0.012429537145848,  0.0121265684425355, 0.0110426354025324, 0.0104341992461836, 0.010373758112336,  0.0101772606932932), cume.pct.of.total = c(0.113817337305101,  0.237124763149948, 0.377090015198269, 0.481908695451763, 0.610652390679108,  0.714272022740551, 0.759077680710614, 0.819917710900762, 0.917237876073098,  1)), .names = c("depth", "obs", "cume.obs", "mean.resp", "cume.mean.resp",  "cume.pct.of.total")) ) write.csv(dat, file="test.csv") 

apparent success. (most r-people both atomic , recursive vectors , without attributes, umbrella includes lists, dataframes, matrices, arrays, ordinary vectors, , factors, "objects".)

i cannot tell if original gains_test2 object had more besides lists in structure object. print method gain-classed objects seems add information, perhaps not in first 6 lists returned head. have thought if more irregular there have been more attributes, perhaps complexities in 7th or higher lists of gains-object.

you may find can extract first 10 lists head(gains_test2, 10) , convert dataframe. admit export excel screen-scraping r console output , using data/text columns... dialog. there capture.console function if end wanteing otuput of print-ed object , find object's structure not see on console.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -