Re: [R] question about technieque do with large computation

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Tue 25 Oct 2005 - 03:06:59 EST

ronggui wrote:

> The green book tells:"The basic technique is classic :keep it simple ."A long ,complicated expression or function is less fravorable than" a relatively small computations that combines calls to a few other functions to perform its tasks."
>
> But I don't get the point totally.Can anyone give me an example to make me understand this rules totally?
>
> ps:
> Is it mean that f1 is better than f2? Thank you!
>
>
> f1<-function(x){
> n<-length(x)
> s<-sum(x)
> m<-s/n}
>
> f2<-
> function(x){
> m<-sum(x)/length(x)}

No, it means collecting sensible small parts of the code into separate functions as in

f1 <- function(x, .....){
 x1 <- f1a(x, ......)
 x2 <- f1b(x1, .....)
 x3 <- f1a(x2, .....)
 f1c(x1, x2, x3, .....)

}

which is "better" than

f2 <- function(.....){

##
## many lines calculating stuff as in f1a
##
## many lines calculating stuff as in f1b
##
## many lines calculating stuff as in f1a
##
## many lines calculating stuff as in f1c
##

}

Uwe Ligges

>
> 2005-10-23
>
> ------
> Deparment of Sociology
> Fudan University
>
> My new mail addres is ronggui.huang@gmail.com
> Blog:http://sociology.yculblog.com
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help@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@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 Received on Tue Oct 25 03:18:06 2005

This archive was generated by hypermail 2.1.8 : Tue 25 Oct 2005 - 05:17:26 EST