Hi all:
Thanks in advance for your assistance.
I just started learning R. I'm trying to use the Help and the downloadable
manuals. I am stuck on trying to multiply matrices. Can anyone please
supply a couple of lines of code that I can plug into a fresh console to see
how a double precision (1x3) matrix is multiplied by a double precision
(3x3) matrix? I keep getting an error message,"Error in x%*%A: requires
numeric matrix/vector arguments".
I have some VBA and VB experience (thus a little Object Oriented
programming experience), am I right in beliving that I am not
"dimensioning"
correctly? I have been trying the following example:
A<-matrix
A<-read.csv("test33.csv"), where the data is
A,B,C
1,4,7
2,5,8
3,6,9
x<-c(4,5,6)
x%*%A
ERROR (as shown above)
ALSO, I have downloaded the RExcel add-in, but have not found any reference
manual, etc that describes how to use it. Any suggestions here are
appreciated, as I primarily do my work in Excel.
Are there any good books available that will help me in my quest to become
a more adept user of R? I know I am going to need this package for
multivariate regressions, etc.
Again, thanks in advance for your time and consideration.
On Fri, 16 May 2003 rwatkins at cornerstonelp.com wrote:> I just started learning R. I'm trying to use the Help and the downloadable > manuals. I am stuck on trying to multiply matrices. Can anyone please > supply a couple of lines of code that I can plug into a fresh console to see > how a double precision (1x3) matrix is multiplied by a double precision > (3x3) matrix? I keep getting an error message,"Error in x%*%A: requires > numeric matrix/vector arguments". > > I have some VBA and VB experience (thus a little Object Oriented > programming experience), am I right in beliving that I am not "dimensioning" > correctly? I have been trying the following example: > A<-matrix > A<-read.csv("test33.csv"), where the data is > A,B,C > 1,4,7 > 2,5,8 > 3,6,9You've forgotten header=TRUE, if you don't want A,B,C to be part of your matrix. R comes with a Data Import/Export Manual: please consult it. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
rwatkins at cornerstonelp.com wrote:> I just started learning R. I'm trying to use the Help and the downloadable > manuals. I am stuck on trying to multiply matrices. Can anyone please > supply a couple of lines of code that I can plug into a fresh console to see > how a double precision (1x3) matrix is multiplied by a double precision > (3x3) matrix? I keep getting an error message,"Error in x%*%A: requires > numeric matrix/vector arguments".> A <- matrix(c(1,4,7,2,5,8,3,6,9), ncol=3, byrow=TRUE) > x <- c(3,5,6) > x%*%A [,1] [,2] [,3] [1,] 31 73 115 The result of read.csv is not a matrix, so try the following: A <- as.matrix(A) x%*%A hope this helps, Chuck Cleland
On Fri, 16 May 2003 12:00:42 -0500, an incredible array of electrons
randomly cascading around the Universe collided and turned into words
spewed forth by rwatkins at cornerstonelp.com:
rwatkins at cornerstonelp.com> Hi all:
rwatkins at cornerstonelp.com> Thanks in advance for your assistance.
rwatkins at cornerstonelp.com>
rwatkins at cornerstonelp.com> I just started learning R. I'm trying
to use the Help and the downloadable
rwatkins at cornerstonelp.com> manuals. I am stuck on trying to multiply
matrices. Can anyone please
rwatkins at cornerstonelp.com> supply a couple of lines of code that I
can plug into a fresh console to see
rwatkins at cornerstonelp.com> how a double precision (1x3) matrix is
multiplied by a double precision
rwatkins at cornerstonelp.com> (3x3) matrix? I keep getting an error
message,"Error in x%*%A: requires
rwatkins at cornerstonelp.com> numeric matrix/vector arguments".
rwatkins at cornerstonelp.com>
rwatkins at cornerstonelp.com> I have some VBA and VB experience
(thus a little Object Oriented
rwatkins at cornerstonelp.com> programming experience), am I right in
beliving that I am not "dimensioning"
rwatkins at cornerstonelp.com> correctly? I have been trying the
following example:
rwatkins at cornerstonelp.com> A<-matrix
rwatkins at cornerstonelp.com> A<-read.csv("test33.csv"),
where the
data is
rwatkins at cornerstonelp.com> A,B,C
rwatkins at cornerstonelp.com> 1,4,7
rwatkins at cornerstonelp.com> 2,5,8
rwatkins at cornerstonelp.com> 3,6,9
rwatkins at cornerstonelp.com>
rwatkins at cornerstonelp.com> x<-c(4,5,6)
rwatkins at cornerstonelp.com> x%*%A
rwatkins at cornerstonelp.com> ERROR (as shown above)
rwatkins at cornerstonelp.com>
rwatkins at cornerstonelp.com> ALSO, I have downloaded the RExcel
add-in, but have not found any reference
rwatkins at cornerstonelp.com> manual, etc that describes how to use it.
Any suggestions here are
rwatkins at cornerstonelp.com> appreciated, as I primarily do my work in
Excel.
rwatkins at cornerstonelp.com>
rwatkins at cornerstonelp.com> Are there any good books available
"that will help me in my quest to become
rwatkins at cornerstonelp.com> a more adept user of R? I know I am going
to need this package for
rwatkins at cornerstonelp.com> multivariate regressions, etc.
rwatkins at cornerstonelp.com>
rwatkins at cornerstonelp.com> Again, thanks in advance for your time
and consideration.
rwatkins at cornerstonelp.com>
rwatkins at cornerstonelp.com>
______________________________________________
Couple of thoughts.
A<-matrix # what's the purpose???
A<-read.csv("test33.csv", header=TRUE)
A # just to list your data
and to make sure that A,B,C aren't stuck in there as rows.
Then your command should work (also assuming that you really have
a CSV file). Try ?read.csv
Hope this helps.
You need to convert your data frame as a matrix before your operation. Try this: x %*% as.matrix(A) Regarding a good book, I may not be the best person to answer you. I am aware of the online manuals available at http://www.r-project.org . The manual "An Introduction to R" is my personal best bet. HTH, Jerome On May 16, 2003 10:00 am, rwatkins at cornerstonelp.com wrote:> Hi all: > Thanks in advance for your assistance. > > I just started learning R. I'm trying to use the Help and the > downloadable manuals. I am stuck on trying to multiply matrices. Can > anyone please supply a couple of lines of code that I can plug into a > fresh console to see how a double precision (1x3) matrix is multiplied > by a double precision (3x3) matrix? I keep getting an error > message,"Error in x%*%A: requires numeric matrix/vector arguments". > > I have some VBA and VB experience (thus a little Object Oriented > programming experience), am I right in beliving that I am not > "dimensioning" correctly? I have been trying the following example: > A<-matrix > A<-read.csv("test33.csv"), where the data is > A,B,C > 1,4,7 > 2,5,8 > 3,6,9 > > x<-c(4,5,6) > x%*%A > ERROR (as shown above) > > ALSO, I have downloaded the RExcel add-in, but have not found any > reference manual, etc that describes how to use it. Any suggestions > here are appreciated, as I primarily do my work in Excel. > > Are there any good books available that will help me in my quest to > become a more adept user of R? I know I am going to need this package > for multivariate regressions, etc. > > Again, thanks in advance for your time and consideration. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help