[R] To transform a vector of qualitatives values into a dataframe of quantitatives values

PIKAL Petr petr.pikal at precheza.cz
Wed Dec 11 14:22:20 CET 2013


Hi

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Arnaud Michel
> Sent: Wednesday, December 11, 2013 2:01 PM
> To: R help
> Subject: [R] To transform a vector of qualitatives values into a
> dataframe of quantitatives values
> 
> Hi
> 
>  From the vector
> X <- c(A, A, B, C, B, A, C)

What is A, B and C? If you expect them to be letters, they need to be in parentheses.

> 
> I would like to build the Dataframe :
> data.frame( A=c(1,1,0,0,0,1,0), B=c(0,0,1,0,1,0,0), C=c(0,0,0,1,0,0,1))
> 
> Any ideas ?

X <- sample(letters[1:3], 10, replace=T)
X
 [1] "c" "c" "a" "b" "c" "c" "a" "a" "a" "a"
data.frame(A=(X=="a"), B=(X=="b"), C=(X=="c"))

Petr


> 
> 
> --
> Michel ARNAUD
> Chargé de mission auprès du DRH
> DGDRD-Drh - TA 174/04
> Av Agropolis 34398 Montpellier cedex 5
> tel : 04.67.61.75.38
> fax : 04.67.61.57.87
> port: 06.47.43.55.31
> 
> ______________________________________________
> 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.



More information about the R-help mailing list