Your English is fine, but your intentions are not. This list has a no homework policy.
-- Bert On Tue, Dec 18, 2012 at 1:09 PM, Wanda Iriarte <wanda.iria...@gmail.com>wrote: > Hi again! > > I am doing a course about the R software and I have a couple of doubts. > > In one of the tasks we were asigned, we have to perform a function that > simulates a bus' trip with 25 stops. In each of those stops, between 0 and > 6 people can go on board. And when the total of passengers reaches 44, no > more people can go on board. > > stops <- 25 > > passengers <- 0 > > *register <- numeric(25) > > *bus <- function(register,stops,passengers) { > > register[1] <- passengers > > for (i in 1:stops) { > > *passengers <- passengers + sample(0:6,1) > > *register[i] <- passengers > > *} > > # If the bus isn't full: > > if (passengers >= 44) { > > # Adjustment if it reaches 44 passenger, before the 25th stop: > > register[i:stops] <- 44 > > cat('Full bus!\n') # Warning message... > > break > > *} else { > > # If the loop doesn't stop, a new register must be added: > > register[i] <- passengers > > *} > > # Para ir viendo cuánto hay: > > cat('Stop', i, 'hay', passengers, 'passenger\n') > > } > > plot(register, xlab='Stop', ylab='No. of passengers') > > The parts of the script that start with an asterisc are the sectors that we > should write, so is in there where my mistakes are. > > The problem with my script is that when I get the plot the variable > "passengers" is always zero for all the bus' stops. So it seems that my > loop isn't able to update the value for each iteration. > > I would be very glad, if anyone can detect my error, as I have been many > days stuck on this part and my deadline is tomorrow. > > Thanks a lot in advance to everyone. And thanks to Rainer who has recently > suggested me to include more information so you could be able to help me. > > Wanda > > PS: Sorry for my English! But Spanish is my first language! > > > -- > Br. Wanda Iriarte > Teléfono de Contacto: 091 33 41 17 > > Ãrea Genética > Dpto. de Genética y Mejora Animal > Facultad de Veterinaria, UdelaR > Montevideo, Uruguay > > [[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. > > -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[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.