Last active
May 30, 2019 00:38
-
-
Save LetticiaNicoli/3273836689d83ab509cd1e7ab372fae6 to your computer and use it in GitHub Desktop.
R - Loop e Fatorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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