,",
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 am lo
age-
From: R-help On Behalf Of Val
Sent: Friday, August 4, 2023 10:54 AM
To: r-help@R-project.org (r-help@r-project.org)
Subject: [R] Multiply
Hi all,
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
1.30
>
> If for some reason you need a more general purpose way to do this for
> arbitrary conformant matrices, you can write a function that does this in a
> more general way but perhaps a better idea might be a way to store your
> matrices in files in a way that can be read back in dir
ay but perhaps a better idea might be a way to store your
matrices in files in a way that can be read back in directly or to not
include indices as character columns but as row names.
-Original Message-
From: R-help On Behalf Of Val
Sent: Friday, August 4, 2023 10:54 AM
To: r-help
В 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, 0
Hi all,
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, 0.35
B, 0.42, 0.52
C, 0.65, 0.75",sep=",",header=TRU
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
> 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
>
> [,1] [,2] [,3]
>
If we have the following matrix:
Mat<-matrix(1:9, byrow=TRUE, nrow=3)
Mat
[,1] [,2] [,3]
[1,]123
[2,]456
[3,]789
I would like to have each row multiplied by a different number.
So I would like row 1 multiplied by 3, row2 by 1 and row3 by 0.5
Which woul
Niloofar.Javanrouh 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.
>
On Mon, May 5, 2014 at 10:16 PM, David Winsemius wrote:
>
> On May 5, 2014, at 6:05 PM, Gabor Grothendieck wrote:
>
>> On Mon, May 5, 2014 at 9:43 AM, Niloofar.Javanrouh
>> wrote:
>>>
>>>
>>> hello,
>>> i want to differentiate of L with respect to b
>>> when:
>>>
>>> L= k*ln (k/(k+mu)) + sum(y) *
On May 5, 2014, at 6:05 PM, Gabor Grothendieck wrote:
> On Mon, May 5, 2014 at 9:43 AM, Niloofar.Javanrouh
> 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
>>
On Mon, May 5, 2014 at 9:43 AM, Niloofar.Javanrouh
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 R?
Try th
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.
_
Best Regards
Niloofar.Javanrouh
Ph.D Student of Bi
g] on behalf 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])})
"R-help@r-project.org"
Cc:
Sent: Tuesday, November 13, 2012 7:41 AM
Subject: [R] multiply each row in a matrix with the help of the for loop
Dear R users,
I have this program
aa<-array(rep(0,27),dim=c(3,3,3))
a<-matrix(rep(1,9),ncol=3)
n<-0
for (i in 1:3) {
a[
Dear R users,
I have this program
aa<-array(rep(0,27),dim=c(3,3,3))
a<-matrix(rep(1,9),ncol=3)
n<-0
for (i in 1:3) {
a[i,]<-a[i,]*(-1)
n<-n+1
aa[,,n]<-a[i,]
}
but i real want to multiply each row with -1 according to for loop and after
that to put it in the array.
I w
On Fri, Jun 1, 2012 at 5:23 PM, David Winsemius 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 necessary
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.
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 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 2 if M=3 and by
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 2 if M=3 and by 3.6678 if M=9. How do i make it?
Thanks for your time and interest
--
View this message in context:
http://r.789695.n4.nabble.com/Multiply-variable-by-condition-tp4632086.html
I am familiar with pairwise t-tests, corrections for multiple testing, etc.
however I have a problem whose answer I have not found after extensive R-help
archive and Google searching.
What I have done in the past:
I have N items which are measured, exposed to a condition, and then measured
agai
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
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
802511
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
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 = as.characte
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
802511100
8026
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 a
5, 2010 2:00 PM
> To: r-help@r-project.org
> Subject: [R] Multiply each depth level of an array with another vector
> element
>
> Suppose
>
> x <- array(c(1,1,1,1,2,2,2,2), dim = c(2,2,2))
>
> y <- c(5, 10)
>
>
>
> Now I would like to multiply x[, ,
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
Suppose
x <- array(c(1,1,1,1,2,2,2,2), dim = c(2,2,2))
y <- c(5, 10)
Now I would like to multiply x[, , 1] with y[1] and x[, , 2] with y[2].
Possible solution is a for-loop:
for (i in 1:2) {
x[, , i] * y[i]
}
Another possible solution is this construction:
as.vector(t(replicate(nrow(
Aan: r-help@r-project.org
Onderwerp: [R] Multiply Two Dataframes
Hi,
I have the following two dataframes (Df1 and Df2):
Df1 has a layout like
ID Location Var1 Var2 Var3 . Var20
A Loc2 1 11. 1
A Loc1 0 10. 1
B L
Hi,
I have the following two dataframes (Df1 and Df2):
Df1 has a layout like
ID Location Var1 Var2 Var3 . Var20
A Loc2 1 11. 1
A Loc1 0 10. 1
B Loc1 0 00. 0
A Loc3
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.
data.frame(ID=c(1,2,3),mu=c(1,34000,5),sigma=c
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 loop.
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 e
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 else I try seems to throw an error "non-numeric argument to
0:50 AM
> To: r-help@r-project.org
> Subject: [R] Multiply each column of array by vector component
>
> 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 corr
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
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
?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
>
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
>
>
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 seems so basic but I can't figure out how to do it without a lo
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
?prod
On 24 Oct 2007, at 05:37, Guolian Kang wrote:
> 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 fo
://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
- Original Message -
From: "Guolian Kang" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 24, 2007 5:37 AM
Subject: [R] multiply for vector in R
> Dear All,
>
> Is t
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?
Thank you so much!
Kang
__
Hi
you need the tensor library:
> library(tensor)
> z <- array(runif(27),rep(3,3))
> w <- runif(3)
> w[1]* z[,,1] + w[2]*z[,,2] + w[3]*z[,,3]
[,1] [,2] [,3]
[1,] 1.2700333 1.1920113 0.8015904
[2,] 0.5175217 0.7808569 0.6306053
[3,] 0.8386015 0.6143882 0.6382314
> tens
Hello,
I would like to compute a weighted combination of matrices.
I have a number of matrices, arranged in a 3D-array, say:
z = array(rep(1:3,c(9,9,9)),c(3,3,3))
so that z[,,1] is my first matrix, and z[,,2] and z[,,3] the second and
third one, and a vector of coefficients:
w = rep(1/3,3)
I
49 matches
Mail list logo