Scores well on notational simplicity.
Loses big on computational efficiency (lots of terms multiplied with zero, then
added to the one nonzero term).
---
Jeff NewmillerThe . . Go Liv
Maybe I am missing the point -- but what is wrong with line 3 of:
m=rbind(c(6,4,2),c(3,2,1))
v= c(3,2,1)
m%*%diag(1/v)
# [,1] [,2] [,3]
# [1,]222
# [2,]111
Ted.
On 14-May-2014 15:03:36 Frede Aakmann Tøgersen wrote:
> Have a look at ?sweep
>
> Br. Frede
>
psed
>>5.040.015.06
>>
>> David C
>>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
>> Behalf Of Jeff Newmiller
>> Sent: Wednesday, May 14, 2014 10:28 AM
>> To: carol white; carol white; r-
user system elapsed
>5.040.015.06
>
> David C
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf Of Jeff Newmiller
> Sent: Wednesday, May 14, 2014 10:28 AM
> To: carol white; carol white;
--Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Jeff Newmiller
Sent: Wednesday, May 14, 2014 10:28 AM
To: carol white; carol white; r-h...@stat.math.ethz.ch
Subject: Re: [R] matrix column division by vector
Please post in plain t
Please post in plain text... your email is getting distorted and hard to read
by the HTML.
I don't know how to use do.call for this, but when you understand how vectors
recycle and matrices and arrays are laid out in memory (read the Introduction
to R document if not) then the following comes t
Oh my goodness David! Don't forget that matrices are just vectors in
column major order.
> m/rep(v,e=2)
[,1] [,2] [,3]
[1,]222
[2,]111
(the generalization is obvious)
should be far more efficient and simpler than running apply loops.
-- Cheers,
Bert
Bert Gunter
G
Have a look at ?sweep
Br. Frede
Sendt fra Samsung mobil
Oprindelig meddelelse
Fra: carol white
Dato:14/05/2014 16.53 (GMT+01:00)
Til: r-h...@stat.math.ethz.ch
Emne: [R] matrix column division by vector
Hi,
What is the elegant script to divide the columns of a matrix by the res
You don't need do.call:
> t(t(m)/v)
[,1] [,2] [,3]
[1,]222
[2,]111
> t(apply(m, 1, function(x) x/v))
[,1] [,2] [,3]
[1,]222
[2,]111
-
David L Carlson
Department of Anthropology
Texas A&M University
Coll
9 matches
Mail list logo