On Wed, 2008-07-02 at 10:32 +0200, Bjørn-Helge Mevik wrote: > Gavin Simpson <[EMAIL PROTECTED]> writes: > > > Ok, lets sort this out. [Not tested as I don't have your data] > > > > df <- data.frame(resp = cancerv1[, 408], > > VARS = as.matrix(cancerv1[, 2:407]) > > Actually, you _do_ need an I() here: > > df <- data.frame(resp = cancerv1[, 408], > VARS = I(as.matrix(cancerv1[, 2:407]))) > > otherwise data.frame() will split the matrix into single coloumn variables.
Doh! Thanks for pointing that out! I knew I'd get something seriously wrong there when I added the immortal words "Not tested...". That'll teach me to take shortcuts and not use dummy or inbuilt data as an example. This raises another issue: > dat <- data.frame(matrix(rnorm(101 * 20), ncol = 101, nrow = 20)) > df <- data.frame(resp = dat[,1], VARS = I(as.matrix(dat[, 2:101]))) > str(df) 'data.frame': 20 obs. of 2 variables: $ resp: num 0.149 -0.715 0.069 0.560 -0.321 ... $ VARS: AsIs [1:20, 1:100] 0.602859.... 0.517785.... -1.02003.... -2.70378.... -0.95322.... ... ..- attr(*, "dimnames")=List of 2 .. ..$ : NULL .. ..$ : chr "X2" "X3" "X4" "X5" ... > class(df$VARS) [1] "AsIs" The class is AsIs for $VARS. But if I look at your yarn data set for example, the NIR component is of class "matrix": > str(yarn) 'data.frame': 28 obs. of 3 variables: $ NIR : num [1:28, 1:268] 3.07 3.07 3.08 3.08 3.10 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : NULL .. ..$ : NULL $ density: num 100.0 80.2 79.5 60.8 60.0 ... $ train : logi TRUE TRUE TRUE TRUE TRUE TRUE ... > class(yarn$NIR) [1] "matrix" How did you achieve this? Cheers G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% ______________________________________________ R-help@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.