Please use colMeans()! was: Re: [R] Calculate Mean of ColumnVectors?
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.ac.be
Tue Jan 11 10:13:57 CET 2005
Hi Tom,
There is the "R Reference Card" by Tom Short and Rpad, which is
extremely useful for a quick browsing of basic R functions. Check:
http://tolstoy.newcastle.edu.au/R/help/04/12/9637.html
For instance, colSums() and friends are in the "Matrices" section.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Mulholland, Tom" <Tom.Mulholland at dpi.wa.gov.au>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, January 11, 2005 9:51 AM
Subject: RE: Please use colMeans()! was: Re: [R] Calculate Mean of
ColumnVectors?
> There are indeed speed advantages in using colSums etc. However the
> disadvantage is that the newbie doesn't always find the power
> inherent in the apply, sapply, tapply and mapply. For many things
> that I do, the speed is the least of my worries; although I take the
> point that using apply for means or sums in packages that are
> distibuted to others is not the way to go.
>
> As many of us have found out (and I think it was in S Poetry) the
> statement was made that vectorisation befuddles some beginners. So
> learning how to use this command, on a nice easy topic such as
> summing or averaging does have some merit. I have to admit using
> colSums a lot, but I don't think I have ever thought to use
> colMeans.
>
> As an aside; does anyone have a list of optimised functions. That is
> functions like this one whose main benefit is speed (I think) I
> guess many of us feel that we are constantly using hammers to crack
> the nuts, but we still don't really know what's in the toolbox.
>
> Tom
>
>> -----Original Message-----
>> From: Uwe Ligges [mailto:ligges at statistik.uni-dortmund.de]
>> Sent: Tuesday, 11 January 2005 3:57 PM
>> To: r-help at stat.math.ethz.ch
>> Cc: 'Thomas Hopper'
>> Subject: Please use colMeans()! was: Re: [R] Calculate Mean of
>> Column
>> Vectors?
>>
>>
>> Folks, please see ?colMeans (as already pointed out in at least one
>> message) and friends.
>> These are faster than those apply(X, 2, mean) calls
>> and please do use them when publishing code (both in packages
>> in on this
>> list).
>>
>> Uwe Ligges
>>
>>
>> >>Hello,
>> >>
>> >>I've got an array defined as y <- rnorm(3000), dim(y) <- c(3,
>> >>1000).
>> >>
>> >>I'd like to produce a 1000-element vector z that is the mean of
>> >>the
>> >>corresponding elements of y (like z[1,1] <- mean(y[1,1], y[2,1],
>> >>y[3,1])), but being new to R, I'm not sure how to do this for all
>> >>elements at once (or, at least, simply). Any help is appreciated.
>> >>
>> >>Thanks,
>> >>
>> >>Tom
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list