[R] If, else, else if, while, for loops


[R] If, else, else if, while, for loops

If 함수 if (x==10) { print('x is equal to 10') } else if (x == 12){ print('x is equal to 12') } else{ print('x is not equal to 10 or 12') } While 함수로 loop 만들기 x <- 0 # x 는 0에서 시작 while (x <10){ # x가 10보다 작을때 print (paste('x is: ', x)) # "x is: "와 x값을 이어서 출력 (paste 함수) x <- x+1 # x 에 1을 더해주고 다시 while 함수로 돌아감(loop) } # 처음의 조건문 (X<10) 을 만족하지 못할때 끝 paste0 -> 사이 간격없이 출력 paste(x, y, sep = "/") -> seperator를 지정 For loop vec <- c(1,2,3,4,5) # vec 라는 벡터 for (var in vec) { # vec안의 변수들에 대하여(var은 임시명, 뭐로든 바꿔도...


#else #for #function #if #loop #R #while

원문링크 : [R] If, else, else if, while, for loops