我正在寻找一种将类似表格的 R 对象导出到 excel/csv 的方法。例如增益表,在 R 中它被保存为一个对象。通常的 write.table 函数不允许我将对象转换为 csv。虽然对象就像一张桌子......:
收益(实际,预测,组=10,最佳=假,百分比=假)->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"' into a data.frame
任何的想法?谢谢!
==================================================== =======================