[ad_1]
[Esteartigofoipublicadopelaprimeiravezem[Thisarticlewasfirstpublishedon R-posts.com, e gentilmente contribuiu para os R-blogueiros]. (Você pode relatar um problema sobre o conteúdo desta página aqui)
Deseja compartilhar seu conteúdo com R-blogueiros? clique aqui se você tiver um blog ou aqui se não tiver.
Como o post em As funções do “olá mundo” foram bastante apreciadas pela comunidade R, segue-se a segunda rodada de funções para o aspirante a programador R.
# If else statement: # See the code syntax below for if else statement x=10 if(x>1){ print(“x is greater than 1”) }else{ print(“x is less than 1”) } # See the code below for nested if else statement x=10 if(x>1 & x8 & x 4) { break } } # Break statement: # A break statement is used in a loop to stop the iterations and flow the control outside of the loop. #Below code shows break statement: x = 1:10 for (i in x){ if (i == 6){ break } print(i) } # Next statement: # Next statement enables to skip the current iteration of a loop without terminating it. #Below code shows next statement x = 1: 4 for (i in x) { if (i == 2){ next } print(i) } # function words = c(“R”, “datascience”, “machinelearning”,”algorithms”,”AI”) words.names = function(x) { for(name in x){ print(name) } } words.names(words) # Calling the function # extract the elements above the main diagonal of a (square) matrix # example of a correlation matrix cor_matrixAs programming is the best way to learn and think, have fun programming awesome functions!
This post is also shared in R-bloggers and LinkedIn
A single loop is not enough. A collection of hello world control structures was first posted on July 13, 2020 at 5:47 am.
©2020 "R-posts.com". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at [email protected]Related
[ad_2]