[R] Dataframes in PLS package

Bjørn-Helge Mevik b.h.mevik at usit.uio.no
Mon Mar 5 11:23:26 CET 2012


westland <westland at uic.edu> writes:

> R still doesn't seem to recognize the data.frame ...  I get a [6] ERROR: 
> object 'depy.w' not found from the following code:
>
> dep <- pls[,1:4]
> ind <- pls[,5:8]
> eqn <- data.frame(depy = dep, indx = ind) 
> apls <- plsr(depy.w + depy.h + depy.d + depy.s ~ indx.a + indx.i + indx.r +
> indx.x,  data=eqn)
>
>
> BUT .... I DID try to cbind() these after add-concatenating them (not sure
> exactly what I am doing) like so ...
>
> apls <- plsr(cbind(depy.w ,depy.h , depy.d , depy.s) ~ cbind(indx.a , indx.i
> , indx.r,indx.x), data=eqn)

For creating multi-coloumn responses on-the-fly, using cbind() like this
works.  However, you don't need that for the predictors; there you can
get by with just using '+'.

If you only have a few predictors/responses, this will work okay, but if
you have many, it will take a lot of typing, and make the
formula handling part of plsr() take _ages_.  Then using matrices is
easier and faster.

-- 
Bjørn-Helge Mevik



More information about the R-help mailing list