Oettli
> Cc: r-help@r-project.org
> Sent: Tuesday, May 21, 2013 5:19 AM
> Subject: Re: [R] Using loop for applying function on matrix
>
> Thanks for your reply Pascal.
> I am presently using it with sweep. But here in the question I just gave
> one simple example. In reality I ne
80 81.81818 55.6
#[5,] 35.714286 40.0 70 72.72727 22.2
A.K.
- Original Message -
From: Suparna Mitra
To: Pascal Oettli
Cc: r-help@r-project.org
Sent: Tuesday, May 21, 2013 5:19 AM
Subject: Re: [R] Using loop for applying function on matrix
Thanks for your reply Pascal
Thanks for your reply Pascal.
I am presently using it with sweep. But here in the question I just gave
one simple example. In reality I need several functions to run. Thus I
was wondering, if without sweep, I can use loop. Also want to learn how to
do this using loop.
Any help will be really grea
Hello,
If you *really* need a loop:
Data <- array(NA, dim(mdat))
for(i in 1:ncol(mdat)){
Data[,i] <- mdat[,i]*100/x[i]
}
But I would consider first the thread cited by Berend.
Regards,
Pascal
On 05/21/2013 06:19 PM, Suparna Mitra wrote:
Thanks for your reply Pascal.
I am presently using
On 21-05-2013, at 09:16, Suparna Mitra wrote:
> Hello R Experts,
> I need a bit of help in using loop.
> I have a matrix onto which I need to use several functions.
>
> In a simplified form suppose my matrix is
>> mdat
> [,1] [,2] [,3] [,4] [,5]
> [1,]12345
> [2,] 11
Hi,
?sweep
mdat <-
matrix(c(1,11,2,10,5,2,12,3,9,6,3,13,4,8,7,4,10,5,9,8,5,10,6,10,4),5,5)
x <- c(14,15,10,11,18)
sweep(mdat*100, 2, x, FUN='/')
[,1] [,2] [,3] [,4] [,5]
[1,] 7.142857 13.3 30 36.36364 27.8
[2,] 78.571429 80.0 130 90.90909 55.6
[3,] 14
6 matches
Mail list logo