Re: [R] Read data from .csv file as a matrix and compare the different between two matrix
On Sep 4, 2012, at 4:39 PM, s.s.m. fauzi wrote: Hi, I have two table matrix, and I would like to compare the different between two matrix. For example: Matrix 1: A B C A 0 1 0 B 0 0 1 C 0 0 0 Matrix 2: A B C A 0 1 0 B 0 0 0 C 0 0 0 Each column which have value 1, should also return value 1. As in this case/example, the result should appear like this (as below). The result of this differentiation should also be in matrix table and should be write in . csv file. Result of the differences: Differences? What differences? If you examined the matrix returned by: matrix1 == matrix2 it would look exactly like your desired result: A B C A 0 1 0 B 0 0 0 C 0 0 0 At the mean time, I'm able to load the .csv file and convert it to matrix matrix1 -read.table(matrix1.csv, header=T, sep=,) matrix1 - as.matrix(matrix1) matrix2 - read.table(matrix2.csv, header=T, sep=,) matrix2 - as.matrix(matrix2) But, I can't find a suitable script to compare the differences between the matrix and write it to file. Appreciate any help from the expert [[alternative HTML version deleted]] __ R-help@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. David Winsemius, MD Alameda, CA, USA __ R-help@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.
Re: [R] Read data from .csv file as a matrix and compare the different between two matrix
Hello, Em 05-09-2012 07:26, David Winsemius escreveu: On Sep 4, 2012, at 4:39 PM, s.s.m. fauzi wrote: Hi, I have two table matrix, and I would like to compare the different between two matrix. For example: Matrix 1: A B C A 0 1 0 B 0 0 1 C 0 0 0 Matrix 2: A B C A 0 1 0 B 0 0 0 C 0 0 0 Each column which have value 1, should also return value 1. As in this case/example, the result should appear like this (as below). The result of this differentiation should also be in matrix table and should be write in . csv file. Result of the differences: Differences? What differences? In fact, this doesn't seem to be a differences problem, but a logical one: - result is 1 iff both operands are 1. So the solution could be # multiply to return an integer, not T/F 1*(matrix1 matrix2) Rui Barradas If you examined the matrix returned by: matrix1 == matrix2 it would look exactly like your desired result: A B C A 0 1 0 B 0 0 0 C 0 0 0 At the mean time, I'm able to load the .csv file and convert it to matrix matrix1 -read.table(matrix1.csv, header=T, sep=,) matrix1 - as.matrix(matrix1) matrix2 - read.table(matrix2.csv, header=T, sep=,) matrix2 - as.matrix(matrix2) But, I can't find a suitable script to compare the differences between the matrix and write it to file. Appreciate any help from the expert [[alternative HTML version deleted]] __ R-help@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. David Winsemius, MD Alameda, CA, USA __ R-help@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. __ R-help@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.
[R] Read data from .csv file as a matrix and compare the different between two matrix
Hi, I have two table matrix, and I would like to compare the different between two matrix. For example: Matrix 1: A B C A 0 1 0 B 0 0 1 C 0 0 0 Matrix 2: A B C A 0 1 0 B 0 0 0 C 0 0 0 Each column which have value 1, should also return value 1. As in this case/example, the result should appear like this (as below). The result of this differentiation should also be in matrix table and should be write in . csv file. Result of the differences: A B C A 0 1 0 B 0 0 0 C 0 0 0 At the mean time, I'm able to load the .csv file and convert it to matrix matrix1 -read.table(matrix1.csv, header=T, sep=,) matrix1 - as.matrix(matrix1) matrix2 - read.table(matrix2.csv, header=T, sep=,) matrix2 - as.matrix(matrix2) But, I can't find a suitable script to compare the differences between the matrix and write it to file. Appreciate any help from the expert [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Read data from .csv file as a matrix and compare the different between two matrix
Hi, Not quite understand your question. Suppose the columns of one matrix (matrix1) have multiple 1's while matrix 2 have only 0's, do you mean that the difference should be 0 for that column? Anyway, the result that you wanted for this example can be got from: mat1-read.table(text= A B C 0 1 0 0 0 1 0 0 0 ,sep=,header=TRUE) mat2-read.table(text= A B C 0 1 0 0 0 0 0 0 0 ,sep=,header=TRUE) library(plyr) join(mat1,mat2,type=inner) # A B C #1 0 1 0 #2 0 0 0 #3 0 0 0 #This solution may not work in situations like the one I mentioned above. A.K. - Original Message - From: s.s.m. fauzi ssmf...@gmail.com To: r-help@r-project.org Cc: Sent: Tuesday, September 4, 2012 7:39 PM Subject: [R] Read data from .csv file as a matrix and compare the different between two matrix Hi, I have two table matrix, and I would like to compare the different between two matrix. For example: Matrix 1: A B C A 0 1 0 B 0 0 1 C 0 0 0 Matrix 2: A B C A 0 1 0 B 0 0 0 C 0 0 0 Each column which have value 1, should also return value 1. As in this case/example, the result should appear like this (as below). The result of this differentiation should also be in matrix table and should be write in . csv file. Result of the differences: A B C A 0 1 0 B 0 0 0 C 0 0 0 At the mean time, I'm able to load the .csv file and convert it to matrix matrix1 -read.table(matrix1.csv, header=T, sep=,) matrix1 - as.matrix(matrix1) matrix2 - read.table(matrix2.csv, header=T, sep=,) matrix2 - as.matrix(matrix2) But, I can't find a suitable script to compare the differences between the matrix and write it to file. Appreciate any help from the expert [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.