[R] R PLS package data format

Peter Ehlers ehlers at ucalgary.ca
Mon Jun 27 15:36:28 CEST 2011


On 2011-06-27 03:02, 新鼎-智慧製造事業處-鄭紹文 wrote:
> Dear sir,
>
> If I have a vector as:
>> y<- c(1:4)
> and a matrix as:
>> x<- matrix (5:12, nrow=4, ncol=2)
>
> Then I create a data frame as:
>> t<- data.frame(y, x)
>
> R will generate a data frame of 3 columns
>> names(t)
>> "y"  "X1" "X2"
>> is.vector(t$X1) returns TRUE
>> is.vector(t$X2) returns TRUE
> R splits the columns of a matrix into column vectors automatically.
>
> How should I create a data frame of t$y&  t$x such that
>> is.vector(t$y) returns TRUE
>> is.matrix(t$x) returns TRUE
> That is, how to make x column of the data frame a matrix? Just like the test data ¡§gasoline¡¨ in your PLS package:
>> library(pls)
>> data(yarn)
>> is.vector(density) returns TRUE
>> is.matrix(NIR) returns TURE (NIR is a matrix)

This is all perfectly well described in ?data.frame where
you will also find reference to the use of I() to
accomplish your goal.

Peter Ehlers

>
> Best regards,
> Shaowen Cheng
>
> ________________________________
> The information in this e-mail may be confidential; it...{{dropped:5}}



More information about the R-help mailing list