[R] R PLS package data format
Patrizio Frederic
frederic.patrizio at gmail.com
Mon Jun 27 15:03:42 CEST 2011
hi,
because of my ignorance I can't figure out why would you need such a structure.
However the following trick works:
> a <- matrix(1:6,3)
> b <- data.frame(1:3)
> b$a <- a
> b
X1.3 a.1 a.2
1 1 1 4
2 2 2 5
3 3 3 6
> names(b)
[1] "X1.3" "a"
> class(b$a)
[1] "matrix"
> is.matrix(b$a)
[1] TRUE
hope that's help
PF
2011/6/27 新鼎-智慧製造事業處-鄭紹文 <shaowencheng at acs.com.tw>:
> 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)
>
> Best regards,
> Shaowen Cheng
>
> ________________________________
> The information in this e-mail may be confidential; it is intended for use solely by the individual or entity named as the recipient hereof. Disclosure, copying, distribution, or use of the contents of this e-mail by persons other than the intended recipient may violate applicable laws and if you have received this e-mail in error, please delete the original message and notify us by collect call immediately. Thank you.
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at 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.
>
>
--
+-----------------------------------------------------------------------
| Patrizio Frederic,
| http://www.economia.unimore.it/frederic_patrizio/
+-----------------------------------------------------------------------
More information about the R-help
mailing list