Skip to content
Prev 323906 / 398503 Next

Using loop for applying function on matrix

You could also use:

? sapply(seq_len(ncol(mdat)),function(i) mdat[,i]*100/x[i])
#????????? [,1]???? [,2] [,3]???? [,4]???? [,5]
#[1,]? 7.142857 13.33333?? 30 36.36364 27.77778
#[2,] 78.571429 80.00000? 130 90.90909 55.55556
#[3,] 14.285714 20.00000?? 40 45.45455 33.33333
#[4,] 71.428571 60.00000?? 80 81.81818 55.55556
#[5,] 35.714286 40.00000?? 70 72.72727 22.22222
A.K.

----- Original Message -----
From: Suparna Mitra <suparna.mitra.sm at gmail.com>
To: Pascal Oettli <kridox at ymail.com>
Cc: r-help at 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 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 great,
Thanks,
Mitra

Dr. Suparna Mitra
Department of Molecular and Clinical Pharmacology
Institute of Translational Medicine University of Liverpool
Block A: Waterhouse Buildings
1-5 Brownlow Street
Liverpool
L69 3GL

Tel.? +44 (0)151 795 5414
M: +44 (0) 7523228621
Internal ext: 55401
On 21 May 2013 16:29, Pascal Oettli <kridox at ymail.com> wrote:

            
??? [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.