Discussion 04 - LoopsConditionalsEtc

# Discussion 04 - LoopsConditionalsEtc - Masanao Yajima You...

This preview shows pages 1–6. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Masanao Yajima You can specify conditional statement as • if( condition ){ } • if( condition ){ } else{ } • if( condition ){ } else if( condition ){} else{} Condition must be a statement that returns a TRUE or FALSE ==: elements on left and right are “same” !=: elements on the left and right are different >, < , <=, >=: greater, less than, etc.. When you have more than one element you are comparing you will get TRUE or FALSE for each of the element. > A <- 1:4 > A == 1 [1] TRUE FALSE FALSE FALSE > A < 3 [1] TRUE TRUE FALSE FALSE In such case when you want to use the if statement, there are useful functions • any(): returns TRUE if any element in the vector is TRUE. • all(): returns TRUE only when all the element is TRUE. > A <- 1:4 > any(A == 1) [1] TRUE > all(A < 3) [1] FALSE There are few ways to write loops. But basically they are all the same so pick one favorite and stick to it as a beginner....
View Full Document

## This note was uploaded on 01/14/2011 for the course STATS 102A 102A taught by Professor Jandeleeuw during the Fall '10 term at UCLA.

### Page1 / 13

Discussion 04 - LoopsConditionalsEtc - Masanao Yajima You...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online