[R] Fibonacci

Nutter, Benjamin NutterB at ccf.org
Wed Apr 20 14:21:13 CEST 2011


Fibonacci <- c(1, 1)
while (max (Fibonacci) < 500){
  Fibonacci <- c(Fibonacci, sum(tail(Fibonacci, 2))) } 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Georgina Imberger
Sent: Wednesday, April 20, 2011 5:43 AM
To: r-help at r-project.org
Subject: [R] Fibonacci

Hi!

I am trying to work out the code to get a Fibonacci sequence, using the
while() loop and only one variable. And I can't figure it out.

Fibonacci<-c(1,1)
while (max(Fibonacci)<500){
Fibonacci<-c(Fibonacci, (max(Fibonacci) + ?(Fibanacci))) }


How can I tell R to take the value one before the max value? (Without
defining another variable)

(Probably super easy... I am a beginner...)

Thanks,
Georgie

	[[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.


===================================

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News & World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}



More information about the R-help mailing list