[R] Dataframes in PLS package

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


"R. Michael Weylandt" <michael.weylandt at gmail.com> writes:

> Without that though, I'm not sure you need the I(as.matrix.(dep)) and
> I(as.matrix(ind)), I would imagine (untested) that eqn <-
> data.frame(depy = dep, indx = ind) would work (probably better as I()
> changes things just a little).

The I() must be there to prevent data.frame() from separating the
coloumns of the matrices into individual variables in the data frame.
Without I() there will be no variables depy and indx in the data frame.

Try this:

> A <- matrix(1:4, ncol=2)
> B <- matrix(2:5, ncol=2)
> A
     [,1] [,2]
[1,]    1    3
[2,]    2    4
> B
     [,1] [,2]
[1,]    2    4
[2,]    3    5

> ## With I():
> d1 <- data.frame(A = I(A), B = I(B))
> d1
  A.1 A.2 B.1 B.2
1   1   3   2   4
2   2   4   3   5
> names(d1)
[1] "A" "B"
> d1$A
     [,1] [,2]
[1,]    1    3
[2,]    2    4

> ## Without I():
> d2 <- data.frame(A = A, B = B)
> d2
  A.1 A.2 B.1 B.2
1   1   3   2   4
2   2   4   3   5
> names(d2)
[1] "A.1" "A.2" "B.1" "B.2"
> d2$A
NULL
> d2$A.1
[1] 1 2


-- 
Regards,
Bjørn-Helge Mevik



More information about the R-help mailing list