[R] non-numeric argument to binary operator
Bill.Venables at csiro.au
Bill.Venables at csiro.au
Thu Feb 5 05:32:12 CET 2009
You are making difficulties where there are none. Consider
> x1 <- 1:3 # Why c(...)?
> x2 <- 2:4
> x12 <- x1*x2 # element by element product (matlab .* operator)
> x12
[1] 2 6 12
> x12 <- outer(x1, x2) # another possibility - outer product
> x12
[,1] [,2] [,3]
[1,] 2 3 4
[2,] 4 6 8
[3,] 6 9 12
> x12 <- x1 %*% x2 # yet another possibility - inner product
> x12
[,1]
[1,] 20
>
It's probably best if you start learning R by reading the introductory material and trying it out. If the going gets tough, persevere. Trying to learn R directly from R-help can get a bit tedious (on both sides).
Bill Venables
http://www.cmis.csiro.au/bill.venables/
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of cruz
Sent: Thursday, 5 February 2009 1:36 PM
To: r-help at r-project.org
Subject: [R] non-numeric argument to binary operator
Hi,
I compute the value of xi*xj by "for" loops, this how I try:
> x1 <- c(1:3)
> x2 <- c(2:4)
### to compute x1*x2
> (paste("x", 1, sep = ""))*(paste("x", 2, sep = ""))
Error in (paste("x", 1, sep = "")) * (paste("x", 2, sep = "")) :
non-numeric argument to binary operator
>
All comments are appreciated.
Thanks,
cruz
______________________________________________
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