Re: [R] Multiply

2023-08-04 Thread avi.e.gross
,", header = TRUE, stringsAsFactors = F, row.names = 1 )) -Original Message- From: Val Sent: Friday, August 4, 2023 2:03 PM To: avi.e.gr...@gmail.com Cc: r-help@r-project.org Subject: Re: [R] Multiply Thank you, Avi and Ivan. Worked for this particular Example. Yes, I a

Re: [R] Multiply

2023-08-04 Thread Rui Barradas
Às 19:03 de 04/08/2023, Val escreveu: Thank you, Avi and Ivan. Worked for this particular Example. Yes, I am looking for something with a more general purpose. I think Ivan's suggestion works for this. multiplication=as.matrix(dat1[,-1]) %*% as.matrix(dat2[match(dat1[,1], dat2[,1]),-1])

Re: [R] Multiply

2023-08-04 Thread Val
Thank you, Avi and Ivan. Worked for this particular Example. Yes, I am looking for something with a more general purpose. I think Ivan's suggestion works for this. multiplication=as.matrix(dat1[,-1]) %*% as.matrix(dat2[match(dat1[,1], dat2[,1]),-1]) Res=data.frame(ID = dat1[,1], Index =

Re: [R] Multiply

2023-08-04 Thread avi.e.gross
Val, A data.frame is not quite the same thing as a matrix. But as long as everything is numeric, you can convert both data.frames to matrices, perform the computations needed and, if you want, convert it back into a data.frame. BUT it must be all numeric and you violate that requirement by

Re: [R] Multiply

2023-08-04 Thread Ivan Krylov
В Fri, 4 Aug 2023 09:54:07 -0500 Val пишет: > I want to multiply two data frames as shown below, > > dat1 <-read.table(text="ID, x, y, z > A, 10, 34, 12 > B, 25, 42, 18 > C, 14, 20, 8 ",sep=",",header=TRUE,stringsAsFactors=F) > > dat2 <-read.table(text="ID, weight, weiht2 > A, 0.25,

Re: [R] Multiply row of a matrix

2017-02-21 Thread Jeff Newmiller
Why this works does not become clear until you actually pay attention to how matrices are laid out in memory as a vector, and how vector replication works. Those ideas are not that difficult to learn, but they feel different than in other languages (e.g. matlab) and they make a huge difference

Re: [R] Multiply row of a matrix

2017-02-21 Thread William Dunlap via R-help
> Mat * c(3, 1, 0.5) [,1] [,2] [,3] [1,] 3.06 9.0 [2,] 4.05 6.0 [3,] 3.54 4.5 Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Feb 21, 2017 at 8:23 AM, wrote: > If we have the following matrix: > > Mat<-matrix(1:9, byrow=TRUE, nrow=3) > Mat >

Re: [R] multiply of two expressions

2014-05-06 Thread Ben Bolker
Niloofar.Javanrouh javanrouh_n at yahoo.com writes:  hello, i want to differentiate of L with respect to b when: L= k*ln (k/(k+mu)) + sum(y) * ln (1-(k/mu+k))   #(negative binomial ln likelihood) and ln(mu/(mu+k)) = a+bx   #link function how can i do it in R? thank you.

Re: [R] multiply of two expressions

2014-05-05 Thread Gabor Grothendieck
On Mon, May 5, 2014 at 9:43 AM, Niloofar.Javanrouh javanrou...@yahoo.com wrote: hello, i want to differentiate of L with respect to b when: L= k*ln (k/(k+mu)) + sum(y) * ln (1-(k/mu+k)) #(negative binomial ln likelihood) and ln(mu/(mu+k)) = a+bx #link function how can i do it in

Re: [R] multiply of two expressions

2014-05-05 Thread David Winsemius
On May 5, 2014, at 6:05 PM, Gabor Grothendieck wrote: On Mon, May 5, 2014 at 9:43 AM, Niloofar.Javanrouh javanrou...@yahoo.com wrote: hello, i want to differentiate of L with respect to b when: L= k*ln (k/(k+mu)) + sum(y) * ln (1-(k/mu+k)) #(negative binomial ln likelihood) and

Re: [R] multiply of two expressions

2014-05-05 Thread Gabor Grothendieck
On Mon, May 5, 2014 at 10:16 PM, David Winsemius dwinsem...@comcast.net wrote: On May 5, 2014, at 6:05 PM, Gabor Grothendieck wrote: On Mon, May 5, 2014 at 9:43 AM, Niloofar.Javanrouh javanrou...@yahoo.com wrote: hello, i want to differentiate of L with respect to b when: L= k*ln

Re: [R] multiply each row in a matrix with the help of the for loop

2012-11-13 Thread arun
HI, May be this helps: list1-lapply(lapply(1:3,function(i) {aa[1:i,,i]-a[1:i,]*-1  return(aa[,,i])}),function(x) apply(x,2,function(i) ifelse(i==0,1,x))) res-array(unlist(list1),dim=c(nrow(list1[[1]]),ncol(list1[[1]]),length(list1)))  res #, , 1 #  #    [,1] [,2] [,3] #[1,]   -1   -1   -1 #[2,] 

Re: [R] multiply each row in a matrix with the help of the for loop

2012-11-13 Thread D. Rizopoulos
of arun [smartpink...@yahoo.com] Sent: Tuesday, November 13, 2012 15:25 To: Haris Rhrlp Cc: R help Subject: Re: [R] multiply each row in a matrix with the help of the for loop HI, May be this helps: list1-lapply(lapply(1:3,function(i) {aa[1:i,,i]-a[1:i,]*-1 return(aa[,,i])}),function(x) apply(x,2

Re: [R] Multiply variable by condition

2012-06-01 Thread Sarah Goslee
There are several ways. The easiest to understand is probably using if() statements: see ?if for help and examples. Sarah On Fri, Jun 1, 2012 at 11:34 AM, jfca283 jfca...@gmail.com wrote: Hi I need to do something very simple. I have 2 variables, Y and M. I need to multiply Y by 1 if M=1, by

Re: [R] Multiply variable by condition

2012-06-01 Thread David Winsemius
On Jun 1, 2012, at 2:37 PM, Sarah Goslee wrote: There are several ways. The easiest to understand is probably using if() statements: see ?if for help and examples. Sarah I would have thought ifelse() to be the necessary function, but for such simple cases I find boolean math to be clearer.

Re: [R] Multiply variable by condition

2012-06-01 Thread Sarah Goslee
On Fri, Jun 1, 2012 at 5:23 PM, David Winsemius dwinsem...@comcast.net wrote: On Jun 1, 2012, at 2:37 PM, Sarah Goslee wrote: There are several ways. The easiest to understand is probably using if() statements: see ?if for help and examples. Sarah I would have thought ifelse() to be the

Re: [R] Multiply list objects

2011-06-17 Thread Uwe Ligges
Since this example is not reproducible (and you have not quuoted any former code) I can only give advice in principle: 1. Never use 1:length(x) since this will seriously fail if x is a length 0 object. Instead, use seq_along(x) 2. If k is a list, then you probably want to use doubled brackets

Re: [R] Multiply list objects

2011-06-17 Thread Mathijs de Vaan
Sorry, forgot to quote: Hi, I am trying to use the objects from the list below to create more objects. For each year in h I am trying to create as many objects as there are B's keeping only the values of B. Example for 1999: $`1999`$`8025` B B 8025 8026 8027 8028 8029 80251

Re: [R] Multiply list objects

2011-06-17 Thread Uwe Ligges
I still do not get the point for what task this expansion of data may be useful, by I guess you want (in this case probably very inefficient, but other can work out how to improve if interested) to insert after k - lapply(h, function (x) x*0) the lines: for(i in seq_along(k)){ temp -

Re: [R] Multiply list objects

2011-06-16 Thread mdvaan
I am still thinking about this problem. The solution could look something like this (it's net yet working): k-lapply(h, function (x) x*0) # I keep the same format as h, but set all values to 0 years-c(1997:1999) # I define the years for (t in 1:length(years)) { year =

Re: [R] Multiply each depth level of an array with another vector element

2010-08-06 Thread Greg Snow
?sweep -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Maurits Aben Sent: Thursday, August 05, 2010 2:00 PM

Re: [R] Multiply each depth level of an array with another vector element

2010-08-06 Thread Wu Gong
It's interesting that sweep is the slowest one comparing to replicate and rep :) - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/Multiply-each-depth-level-of-an-array-with-another-vector-element-tp2315537p2316586.html Sent from the R help mailing list archive

Re: [R] Multiply each depth level of an array with another vector element

2010-08-05 Thread Wu Gong
I have only achieved a half improvement. x - array(1:2400*1, dim = c(200,300,400)) y - 1:400*1 ptm - proc.time() z - x*as.vector(t(replicate(dim(x)[1]*dim(x)[2], y[1:dim(x)[3]]))) replicate: proc.time() - ptm x - array(1:2400*1, dim = c(200,300,400)) y - 1:400*1 ptm - proc.time() z -

Re: [R] Multiply Two Dataframes

2010-06-07 Thread ONKELINX, Thierry
Dear Bert, The easiest thing would be to merge both datasets and then multiply the corresponding columns. both - merge(df1, df2) both[, 3:22] * both[, 23:42] HTH, Thierry -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org namens Bert Jacobs Verzonden: ma 7-6-2010 20:29 Aan:

Re: [R] Multiply Normal Curves

2009-09-24 Thread KABELI MEFANE
R -helpers   i have been trying to do this problem without must success,i managed to do a graph for x, but it is not what i want to define,(i want to specify number of observations as well). I have also been able to do simple rendom sample.  

Re: [R] Multiply List by a Numeric

2009-08-24 Thread Marc Schwartz
On Aug 24, 2009, at 10:58 AM, Brigid Mooney wrote: I apologize for what seems like it should be a straighforward query. I am trying to multiply a list by a numeric and thought there would be a straightforward way to do this, but the best solution I found so far has a for loop. Everything

Re: [R] Multiply List by a Numeric

2009-08-24 Thread Peter Ehlers
Try lapply(abc, function(x) x*3) Peter Ehlers Brigid Mooney wrote: I apologize for what seems like it should be a straighforward query. I am trying to multiply a list by a numeric and thought there would be a straightforward way to do this, but the best solution I found so far has a for

Re: [R] Multiply each column of array by vector component

2007-11-15 Thread Gabor Grothendieck
On Nov 15, 2007 12:50 PM, [EMAIL PROTECTED] wrote: Hi, I've got an array, say with i,jth entry = A_ij, and a vector, say with jth entry= v_j. I would like to multiply each column of the array by the corresponding vector component, i,e. find the array with i,jth entry A_ij * v_j This

Re: [R] Multiply each column of array by vector component

2007-11-15 Thread Benilton Carvalho
?sweep b On Nov 15, 2007, at 12:50 PM, [EMAIL PROTECTED] wrote: Hi, I've got an array, say with i,jth entry = A_ij, and a vector, say with jth entry= v_j. I would like to multiply each column of the array by the corresponding vector component, i,e. find the array with i,jth entry A_ij

Re: [R] Multiply each column of array by vector component

2007-11-15 Thread Henrique Dallazuanna
If i understand your question, you can do: x - matrix(1:10, 2) y - sample(10,5) apply(x, 1, function(.x)mapply(y, .x, FUN=*)) On 15/11/2007, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I've got an array, say with i,jth entry = A_ij, and a vector, say with jth entry= v_j. I would like to

Re: [R] Multiply each column of array by vector component

2007-11-15 Thread Marc Schwartz
On Thu, 2007-11-15 at 17:50 +, [EMAIL PROTECTED] wrote: Hi, I've got an array, say with i,jth entry = A_ij, and a vector, say with jth entry= v_j. I would like to multiply each column of the array by the corresponding vector component, i,e. find the array with i,jth entry A_ij * v_j

Re: [R] Multiply each column of array by vector component

2007-11-15 Thread Greg Snow
?sweep -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Thursday, November 15, 2007 10:50 AM To:

Re: [R] multiply for vector in R

2007-10-24 Thread ecatchpole
Guolian Kang wrote on 10/24/2007 01:37 PM: Dear All, Is there a conmand to calculate the multiplication of the elements in a vector? For example: a=c(1,2,3,4) I want to get 1*2*3*4=24. Because the dimension of the vector is high, I want to know there is a command for this task in R?