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]]


