Hi Richard, As others have said, try to use the "apply" functions rather than loops. There is also an apply function for lists, see ?lapply. This is much more efficient. I also like writing my own functions. For example:
f <- function(x) { x^2 } Which can then be used by: > f(2) [1] 4 This is very useful if you're getting into maximum likelihood programming, or want to use the "optim" function (for multivariate functions) or "optimize" (for univariate functions). Lastly, check out the R reference card. http://cran.r-project.org/doc/contrib/Short-refcard.pdf Regards, Peter On Tue, Jul 19, 2011 at 12:43, RichardLang <l...@zedat.fu-berlin.de> wrote: > Hi everyone! > > I'm trying to teach myself R in order to do some data analysis. I'm a > mathematics student and (only) familiar with matlab and latex. I'm working > trough the "official" introduction to R at the moment, while simultaneously > solving some exercises I found in the web. Before I post my (probably > stupid) question, I'd like to ask you for some general advice. How do you > work with R? Is it like in matlab, that you write your functions with a lot > of loops etc. in a textfile and then run it? Or do you just prepare your > data and then use the functions provided by R (plot, mean etc) to get some > analysis? I'd be very thankfull for some of your thoughts about > "approaches". > > Now the question: I'm trying to build a vector with n entries, each > consisting of the mean of m random numbers (exponential distributed for > example). My approach was to construct a nxm random matrix and then to > somehow take the mean of each row. But in the mean function there is no > parameter to do this, so the intended approach of R is probably different.. > any ideas? =) > > Richard > > -- > View this message in context: > http://r.789695.n4.nabble.com/calculating-the-mean-of-a-random-matrix-by-row-and-some-general-questions-tp3678964p3678964.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. > > [[alternative HTML version deleted]] ______________________________________________ R-help@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.