Oops -- quite right, Brian. Interesting, as I stared at it for some time. Sigh... now what **WAS** I looking for in the refrigerator?
-- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA > -----Original Message----- > From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] > Sent: Friday, October 07, 2005 12:36 PM > To: Berton Gunter > Cc: 'Tim Smith' > Subject: Re: [R] Applying a function to each element of an array > > On Fri, 7 Oct 2005, Berton Gunter wrote: > > > Well, since Sum(i=1 to i-n) =n*(n+1)/2, your loop simply gives > > 1/4*count*(count-1). > > So if your matrix is A, A*(A-1)/4 is about the quickest way > to get your > > answer I think. > > I think Bert has read ^ as *. > > > > > -- Bert Gunter > > Genentech Non-Clinical Statistics > > South San Francisco, CA > > > > "The business of the statistician is to catalyze the > scientific learning > > process." - George E. P. Box > > > > > > > >> -----Original Message----- > >> From: [EMAIL PROTECTED] > >> [mailto:[EMAIL PROTECTED] On Behalf Of Tim Smith > >> Sent: Friday, October 07, 2005 11:48 AM > >> To: [email protected] > >> Subject: [R] Applying a function to each element of an array > >> > >> Hi, > >> > >> I have a 7000x7000 matrix, and each element is an integer. > >> For each element, I want to apply the function : > >> > >> wt <- 0 > >> for(q in 1:count){ > >> wt <- wt + 0.5^(q-1) > >> } > >> > >> I get the value of 'count' from the elements in the matrix , > >> and want to store the corresponding 'wt' value for that element. > >> > >> I suppose I could loop through the matrix, and apply the > >> function to each element but this would take a really really > >> long time. Are there any quicker ways to get the same result? > >> > >> many thanks, > >> > >> Tim > >> > >> > >> --------------------------------- > >> > >> > >> [[alternative HTML version deleted]] > >> > >> ______________________________________________ > >> [email protected] mailing list > >> https://stat.ethz.ch/mailman/listinfo/r-help > >> PLEASE do read the posting guide! > >> http://www.R-project.org/posting-guide.html > >> > > > > ______________________________________________ > > [email protected] mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > > > -- > Brian D. Ripley, [EMAIL PROTECTED] > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UK Fax: +44 1865 272595 > ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
