Dear R helpers, I have been using the loadings function from the multiv library and I get the typical output (see below). When I try to export these results to a file using a write.table() I get the following error message "Error in as.data.frame.default(x[[i]], optional = TRUE) : can't coerce loadings into a data.frame" Any idea why write.table is doing that and any possible solutions?? thanks hector > loadings(M2.princomp.corr) Loadings: Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8 Comp.9 Comp.10 f61 0.158 -0.138 -0.341 f63 0.234 -0.359 f67 0.178 -0.113 -0.329 f75 0.187 -0.199 0.143 0.135 0.160 f78 -0.166 -0.193 -0.168 0.154 f81 -0.123 -0.102 -0.125 -0.284 0.297 f115 0.161 0.203 -0.199 -0.103 -0.225 f117 0.166 0.198 -0.198 -0.241 f123 0.184 -0.111 -0.157 0.209 -0.231 f125 0.224 -0.169 f135 0.159 0.205 -0.200 -0.103 -0.226 f138 0.248 0.210 0.151 0.123 -0.282 f161 -0.152 -0.242 -0.114 f163 -0.212 -0.183 0.133 0.196 f176 0.248 0.210 0.151 0.123 -0.282 f180 0.162 0.191 0.225 0.206 -0.104 0.324 f182 0.229 -0.229 -0.178 f185 0.226 0.125 -0.109 f190 0.227 -0.233 -0.201 -0.103 f193 -0.158 0.214 -0.327 -0.106 f196 -0.158 0.212 -0.332 -0.108 f199 -0.156 0.212 -0.335 -0.109 f203 -0.202 -0.168 0.113 f210.2 0.175 -0.175 -0.107 0.415 f216 -0.214 0.125 0.227 0.223 -0.145 f225 -0.181 0.234 f227 -0.198 0.214 f230 -0.391 -0.126 Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8 Comp.9 SS loadings 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 Proportion Var 0.018 0.018 0.018 0.018 0.018 0.018 0.018 0.018 0.018 Cumulative Var 0.018 0.036 0.054 0.071 0.089 0.107 0.125 0.143 0.161 Comp.10 Comp.11 Comp.12 Comp.13 Comp.14 Comp.15 Comp.16 Comp.17 SS loadings 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 Proportion Var 0.018 0.018 0.018 0.018 0.018 0.018 0.018 0.018 Cumulative Var 0.179 0.196 0.214 0.232 0.250 0.268 0.286 0.304 Comp.18 Comp.19 Comp.20 Comp.21 Comp.22 Comp.23 Comp.24 Comp.25 SS loadings 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 Proportion Var 0.018 0.018 0.018 0.018 0.018 0.018 0.018 0.018 Cumulative Var 0.321 0.339 0.357 0.375 0.393 0.411 0.429 0.446 Comp.26 Comp.27 Comp.28 Comp.29 Comp.30 Comp.31 Comp.32 Comp.33 SS loadings 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 Proportion Var 0.018 0.018 0.018 0.018 0.018 0.018 0.018 0.018 Cumulative Var 0.464 0.482 0.500 0.518 0.536 0.554 0.571 0.589 Comp.34 Comp.35 Comp.36 Comp.37 Comp.38 Comp.39 Comp.40 Comp.41 SS loadings 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 Proportion Var 0.018 0.018 0.018 0.018 0.018 0.018 0.018 0.018 Cumulative Var 0.607 0.625 0.643 0.661 0.679 0.696 0.714 0.732 Comp.42 Comp.43 Comp.44 Comp.45 Comp.46 Comp.47 Comp.48 Comp.49 SS loadings 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 Proportion Var 0.018 0.018 0.018 0.018 0.018 0.018 0.018 0.018 Cumulative Var 0.750 0.768 0.786 0.804 0.821 0.839 0.857 0.875 > write.table(loadings(M2.princomp.corr)) Error in as.data.frame.default(x[[i]], optional = TRUE) : can't coerce loadings into a data.frame
On Thu, 24 Apr 2003, Hector L. Ayala-del-Rio wrote:> Dear R helpers, > I have been using the loadings function from the multiv library and ILooks like loadings() from the *mva* package to me, or more precisely the result of the print method for loadings.> get the typical output (see below). When I try to export these results > to a file using a write.table() I get the following error message > "Error in as.data.frame.default(x[[i]], optional = TRUE) : can't coerce > loadings into a data.frame" Any idea why write.table is doing that and > any possible solutions???write.table says `write.table' prints its required argument `x' (after converting it to a data frame if it is not one already) to `file'. There is no in-built way to convert a `loadings' object to a data frame, but as it is a matrix (see ?princomp), unclass(loadings(foo)) will work.> > write.table(loadings(M2.princomp.corr))^unclass( ^) Note that you do get just the loadings, not the full output from print.loadings. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595