Re: [R] Matrix element-by-element multiplication

2015-09-29 Thread Rolf Turner
On 30/09/15 12:49, waddawanna wrote: Hello Steven, It looks like, there is no in-built function that can do GAUSS ".*" element-wise multiplication. Now, if you want to make the desired computations in R, it is actually preatty straightforward. a<-c(1,2,3) b<-matrix(rep(1:9,1),3,3,byrow=TRUE)

Re: [R] Matrix element-by-element multiplication

2015-09-29 Thread David Winsemius
On Sep 29, 2015, at 4:49 PM, waddawanna wrote: > Hello Steven, > > It looks like, there is no in-built function that can do GAUSS ".*" > element-wise multiplication. > Now, if you want to make the desired computations in R, it is actually > preatty straightforward. > >> a<-c(1,2,3) >>

[R] Matrix element-by-element multiplication

2015-01-07 Thread Steven Yen
I like to multiple the first and second column of a 10 x 3 matrix by 100. The following did not work. I need this in an operation with a much larger scale. Any help? aa-matrix(1:30,nrow=10,ncol=3); aa bb-matrix(c(100,100,1),nrow=1,ncol=3); bb dim(aa) dim(bb) aa*bb Results:

Re: [R] Matrix element-by-element multiplication

2015-01-07 Thread John McKown
On Wed, Jan 7, 2015 at 5:05 PM, Steven Yen sye...@gmail.com wrote: I like to multiple the first and second column of a 10 x 3 matrix by 100. The following did not work. I need this in an operation with a much larger scale. Any help? aa-matrix(1:30,nrow=10,ncol=3); aa

Re: [R] Matrix element-by-element multiplication

2015-01-07 Thread Peter Langfelder
You can create a suitable matrix bb as below (note the byrow = TRUE argument) aa-matrix(1:30,nrow=10,ncol=3); aa bb-matrix(c(100,100,1),nrow=10,ncol=3, byrow = TRUE); bb dim(aa) dim(bb) aa * bb You can also use matrix multiplication, but that;s slightly more involved:

Re: [R] Matrix element-by-element multiplication

2015-01-07 Thread Peter Langfelder
On Wed, Jan 7, 2015 at 3:15 PM, Peter Langfelder peter.langfel...@gmail.com wrote: You can create a suitable matrix bb as below (note the byrow = TRUE argument) aa-matrix(1:30,nrow=10,ncol=3); aa bb-matrix(c(100,100,1),nrow=10,ncol=3, byrow = TRUE); bb dim(aa) dim(bb) aa * bb You can

Re: [R] Matrix element-by-element multiplication

2015-01-07 Thread Steven Yen
Thank you both. Both John and Peter's suggestions work great!! At 06:17 PM 1/7/2015, John McKown wrote: On Wed, Jan 7, 2015 at 5:05 PM, Steven Yen mailto:sye...@gmail.comsye...@gmail.com wrote: I like to multiple the first and second column of a 10 x 3 matrix by 100. The following did not

Re: [R] Matrix element-by-element multiplication

2011-11-06 Thread David Winsemius
On Nov 6, 2011, at 12:21 AM, R. Michael Weylandt wrote: There are a few (nasty?) side-effects to c(), one of which is stripping a matrix of its dimensionality. E.g., x - matrix(1:4, 2) c(x) [1] 1 2 3 4 So that's probably what happened to you. R has a somewhat odd feature of not really

Re: [R] Matrix element-by-element multiplication

2011-11-06 Thread R. Michael Weylandt michael.weyla...@gmail.com
It looks like pdf is not a scalar (that term actually has no meaning in R but I know what you mean) but is rather a 1x1 matrix, as attested by the fact it has dimensions. If you give dnorm() a matrix it will return one, as it did here. Perhaps you should look at the is.matrix() and

Re: [R] Matrix element-by-element multiplication

2011-11-06 Thread Joshua Wiley
Hi, R may not have a special scalar, but it is common, if informal, in linear algebra to refer to a 1 x 1 matrix as a scalar. Indeed, something like: 1:10 * matrix(2) or matrix(2) * 1:10 are both valid. Even matrix(2) %*% 1:10 and 1:10 %*% matrix(2) work, where the vector seems to be

Re: [R] Matrix element-by-element multiplication

2011-11-06 Thread Steven Yen
Mucha gracias!! as.vector worked like a charm and, in this case, produced the same results as c(): c(pdf)*v as.vector(pdf)*v At 07:02 PM 11/6/2011, R. Michael Weylandt michael.weyla...@gmail.com wrote: It looks like pdf is not a scalar (that term actually has no meaning in R but I

Re: [R] Matrix element-by-element multiplication

2011-11-05 Thread R. Michael Weylandt
There are a few (nasty?) side-effects to c(), one of which is stripping a matrix of its dimensionality. E.g., x - matrix(1:4, 2) c(x) [1] 1 2 3 4 So that's probably what happened to you. R has a somewhat odd feature of not really considering a pure vector as a column or row vector but being

[R] Matrix element-by-element multiplication

2011-11-04 Thread Steven Yen
is there a way to do element-by-element multiplication as in Gauss and MATLAB, as shown below? Thanks. --- a 1.000 2.000 3.000 x 1.0002.0003.000 2.0004.0006.000 3.000

Re: [R] Matrix element-by-element multiplication

2011-11-04 Thread R. Michael Weylandt
Did you even try? a - 1:3 x - matrix(c(1,2,3,2,4,6,3,6,9),3) a*x [,1] [,2] [,3] [1,]123 [2,]48 12 [3,]9 18 27 Michael On Fri, Nov 4, 2011 at 7:26 PM, Steven Yen s...@utk.edu wrote: is there a way to do element-by-element multiplication as in Gauss and