Re: [R] coerce matrix to number

From: Jacques VESLOT <jacques.veslot_at_good.ibl.fr>
Date: Tue 12 Sep 2006 - 17:26:23 GMT

if only 2 letters:
(z=="v")*1
else:
lapply(z, function(x) as.numeric(as.character(factor(x,levels= c("d","v","w"),labels=c(0,1,2)))))



Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr


Simone Gabbriellini a écrit :
> Dear List,
>
> how can I coerce a matrix like this
>
> [,1] [,2] [,3] [,4] [,5] [,6]
> [1,] "0" "1" "1" "0" "0" "0"
> [2,] "1" "0" "1" "0" "0" "0"
> [3,] "1" "1" "0" "0" "0" "0"
> [4,] "0" "0" "0" "0" "1" "0"
> [5,] "0" "0" "0" "1" "0" "0"
> [6,] "0" "0" "0" "0" "0" "0"
>
> to be filled with numbers?
>
> this is the result of replacing some character ("v", "d") with 0 and
> 1, using the code I found with RSiteSearch()
>
> z[] <- lapply(z, factor, levels = c("d", "v"), labels = c(0, 1));
>
> thank you,
> Simone
>
> |-------------------------------------------------|
>
> dott. Simone Gabbriellini
> PhD Student
> Dipartimento di Scienze Sociali
> Università di Pisa
> via Colombo 35 - 56100 Pisa
> mail: simone.gabbriellini@sp.unipi.it
> mobile: +39 3475710037
>
> |-------------------------------------------------|
>
> Please avoid sending me Word or PowerPoint attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html
>
>
> [[alternative HTML version deleted]]
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.



R-help@stat.math.ethz.ch 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. Received on Wed Sep 13 03:46:18 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 12 Sep 2006 - 18:30:04 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.