Re: [R] Need help in matrix multiplication error

From: jim holtman <jholtman_at_gmail.com>
Date: Tue, 20 May 2008 00:50:49 -0400

Is this what you want: you need the 'drop=FALSE' to make sure it stays a matrix.

> data <- read.table(textConnection(" Statement T1001 T1002 T1003 T1004
T1005 T100 T1014 T1021 T1022 T1023

+ 1         0     0     0     0     0     0    0     0     1     0     0
+ 2        0     0     0     0     0     0    0     0     1     0     0
+ 3         0     1     0     0     1     0    0     0     1     0     0
+ 4       0      1      1     0     1    1     1     1     1     1     1"),
header=TRUE)
> data <- as.matrix(data)
> str(data)
 int [1:4, 1:11] 0 0 0 0 0 0 1 1 0 0 ...

On Mon, May 19, 2008 at 7:43 PM, Jason Lee <huajie.lee_at_gmail.com> wrote:

> Hi,
>
> I have a data file which is named test.txt as below. Prior to that, I have
> converted the last row from nominal to numeric using as.integer.
>
> Statement T1001 T1002 T1003 T1004 T1005 T100 T1014 T1021 T1022 T1023
> 1 0 0 0 0 0 0 0 0 1 0 0
> 2 0 0 0 0 0 0 0 0 1 0 0
> 3 0 1 0 0 1 0 0 0 1 0 0
> 4 406 pass pass fail pass pass pass pass pass pass pass
>
> After as.integer of "pass", the below data is been transformed.
>
> Statement T1001 T1002 T1003 T1004 T1005 T100 T1014 T1021 T1022 T1023
> 1 0 0 0 0 0 0 0 0 1 0 0
> 2 0 0 0 0 0 0 0 0 1 0 0
> 3 0 1 0 0 1 0 0 0 1 0 0
> 4 0 1 1 0 1 1 1 1 1 1 1
>
>
> The 1,2,3 and 4 on the first column is the automatic numbering seen on the
> terminal when i pasted here.
>
> And, i try to use matrix multiplication which is
> as.matrix(data[1:3,2:11])%*% sign(t(data[4,2:11]))
> Basically i wanted to count from column 2 onwards..which i want to ignore
> the Statement column data.
>
> Error in sign(t(data[4, 2:11])) : Non-numeric argument to mathematical
> function.
> I try take off the column constraint which is
> as.matrix(data[1:3,])%*% sign(t(data[4,]))
> but it still gives me
> Error in sign(t(data[4, ])) : Non-numeric argument to mathematical function
>
> I didnt understand how this error relate to my data above. Because my data
> is not a character at the first place and its a data.frame.
>
>
> Please help.Thanks..
>
> Rgrds,
> Jason
>
> [[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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[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.
Received on Tue 20 May 2008 - 04:56:33 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 20 May 2008 - 05:30:40 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.

list of date sections of archive