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 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:4] "1" "2" "3" "4"
..$ : chr [1:11] "Statement" "T1001" "T1002"
"T1003" ...> data[1:3,2:11]%*% sign(t(data[4,2:11, drop=FALSE]))
4
1 1
2 1
3 3>
On Mon, May 19, 2008 at 7:43 PM, Jason Lee <huajie.lee@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@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]]