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) >> b<-matrix

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) a

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 ><sye...@gmail.com> wrote: >I like to multiple the first and second column >of a 10 x 3 matrix by 100. The following did no

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

2015-01-07 Thread Peter Langfelder
On Wed, Jan 7, 2015 at 3:15 PM, Peter Langfelder 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 also use matrix mu

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

2015-01-07 Thread John McKown
On Wed, Jan 7, 2015 at 5:05 PM, Steven Yen 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 > bb<-matrix(c(100,100,1),nrow=1,nc

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: aa<-matrix(1:30,nrow=10,

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 wrote: >It looks like pdf is not a "scalar" (that term actually has no >meaning in R but I know what you mean) but is

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 silen

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

2011-11-06 Thread R. Michael Weylandt
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 as.vector

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 consid

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 will

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 wrote: > is there a way to do element-by-element multiplication as in Gauss > and MATLAB, as sh