[R] if ~ else와 ifelse 사용법

R 2015. 11. 25. 15:00


R은 ifelse를 함께 써서 true, false에 대한 처리를 쉽게 처리할 수 있다. 



기존 if, else 관점의 처리 코드이다.
visit_count_from_redis <- if(is.null(visit_count_from_redis)) 0 else visit_count_from_redis

 
이를 ifelse로 변경한 코드이다.
visit_count_from_redis <- ifelse(is.null(visit_count_from_redis), 0, visit_count_from_redis) 


Posted by '김용환'
,