0% found this document useful (0 votes)
5 views3 pages

Business Analytics Summary

Sessions 3 and 4 of Business Analytics cover iterator instructions and advanced object types in R. Session 3 discusses the `while` and `repeat` loops for executing code based on conditions, along with the use of functions for code reusability. Session 4 introduces vectors and matrices, explaining their creation and manipulation in R.

Uploaded by

sanikajadhav0401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Business Analytics Summary

Sessions 3 and 4 of Business Analytics cover iterator instructions and advanced object types in R. Session 3 discusses the `while` and `repeat` loops for executing code based on conditions, along with the use of functions for code reusability. Session 4 introduces vectors and matrices, explaining their creation and manipulation in R.

Uploaded by

sanikajadhav0401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Summary of Business Analytics - Sessions 3 & 4

Summary of Business Analytics - Session 3

**Topic: Iterator Instructions in R**

### 1. Iterator Pattern in R: While Instruction


- The `while` loop executes instructions as long as a condition holds true.
- Syntax:
```r
while(condition) {
commands to be executed
}
```
- The condition is checked first; if false, the loop does not execute.
- Example: Compute the sum of the first N natural numbers.
```r
N <- 10
i <- 1
sum <- 0
while (i <= N) {
sum <- sum + i
i <- i + 1
}
print(sum)
```
- **Caution:** Avoid infinite loops by ensuring the condition eventually becomes false.

### 2. Iterator Pattern in R: Repeat Instruction


- The `repeat` loop executes a block of code repeatedly until explicitly stopped.
- Syntax:
```r
repeat {
commands to be executed
if (exit condition) {
break
}
}
```
- Example:
```r
N <- 10
i <- 1
sum <- 0
repeat {
sum <- sum + i
i <- i + 1
if (i > N) {
break
}
}
print(sum)
```

### 3. Functions in R
- Functions allow repeated use of code with different inputs.
- Example: Function to calculate the area of a circle.
```r
areaofCircle <- function(R) {
Area <- 3.14 * (R^2)
return(Area)
}
print(areaofCircle(5)) # Output: 78.5
```

---
End of Summary for Session 3.

Summary of Business Analytics - Session 4

**Topic: Advanced Object Types in R**

### 1. Vectors in R
- A vector is a group of data objects of the same type.
- Created using `c()` function:
```r
groupofInt <- c(1, 15, 11, -7)
```
- Mathematical operations apply element-wise:
```r
c(3,4,5) * 2 # Results: c(6, 8, 10)
```

### 2. Accessing and Modifying Vector Elements


- Individual elements accessed using index:
```r
v <- c(3,6,-7,5)
v[2] # Output: 6
```

### 3. Matrices in R
- A matrix is a 2D collection of data objects of the same type.
- Created using `matrix()` function:
```r
matrixM <- matrix(c(1,2,3,4,5,6), nrow=3, ncol=2)
```

---
End of Summary for Session 4.

You might also like