Skip to content

Instantly share code, notes, and snippets.

@LetticiaNicoli
Last active May 30, 2019 00:38
Show Gist options
  • Save LetticiaNicoli/3273836689d83ab509cd1e7ab372fae6 to your computer and use it in GitHub Desktop.
Save LetticiaNicoli/3273836689d83ab509cd1e7ab372fae6 to your computer and use it in GitHub Desktop.
R - Loop e Fatorial
#Loop
AirPassengers
acumuladora = 0;
vetor = NULL;
for (passenger in AirPassengers) {
acumuladora = acumuladora + passenger;
vetor = c(vetor, acumuladora);
}
print(vetor)
?ts
ts(data = vetor, frequency = 12, start = c(1949,1))
air = AirPassengers
for (i in seq_along(AirPassengers)) {
air[i] = vetor[i]
}
air
#Fatorial
func = function(num){
init = 1;
for (variable in seq_len(num)) {
init = init * variable;
}
init
}
func(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment