Publications by Anastasia Bernat
Lesson 10 - Introduction to Functions
Lesson 10 | 20 May 2020 What are Functions? Another key and one of my personal favorites is the ability for the user, like you and I, to make functions in R. They help clean up repeatitive calculations/code/specific tasks into an easy and accessible block of statements that can be called whenever you need it again. You’ve seen a lot of R’s n...
3209 sym R (3028 sym/14 pcs)
Problem Set 6 - Solutions
Problem Set 6 | 13 May 2020 - 20 May 2020 at 10 AM Problem 1. Write a while-while loop (nested while loop) that evaluates b until it’s equal to 3 and x until it’s equal to 5. b <- 0 while (b <= 3) { x <- 0 cat("b --------", b, end='\n') while (x <= 5) { cat("x", x, end='\n') x <- x + 1 } b <- b + 1 } ## b -------- 0 ## x 0...
2963 sym R (1142 sym/7 pcs)
Lesson 9 - Nested Loops Part 3
Lesson 9 | 13 May 2020 Nested Loops Continued Now that’s you’ve gotten a hang of nested-for-loops and the nuances of R data structures, let’s look into nested loops using control-flow constructs such as while or repeat. While-While Loop A nested while loops sounds just as you think, a while loop embbeded in another while loop. Example 1: ...
5634 sym R (5092 sym/39 pcs)
Problem Set 5 - Solutions
Problem Set 5 | 6 May 2020 - 13 May 2020 at 10 AM Answer the following conceptual questions. (i) Other than its contents, what are the three properties of a vector? The three properties of a vector are type, length, and attributes. temp <- c(1,2,3,4,5) print(typeof(temp)) ## [1] "double" print(length(temp)) ## [1] 5 print(attributes(temp)) ## NU...
3684 sym R (5110 sym/37 pcs)
Problem Set 4 - Solutions
Problem Set 4 | 15 April 2020 - 22 April 2020 at 10 AM Below there are 2 nested for loop questions, but please be sure to answer the questions that proceed the ‘#’ in the R code blocks. Problem 1. Write a nested for loop that will print the following output: 1 2 2 3 3 3 4 4 4 4 Hint: use the cat function to print correctly. for (i in seq(1:4)...
591 sym R (1184 sym/6 pcs)
Lesson 8 - R Data Structures Review
Lesson 8 | 6 May 2020 Addressing issues we bumped into last time Let’s take a pause from the nested-loop work we’ve been doing to address some of the nuances of the R programming language and its data structures. (1) else if statemetns in R. (else if = elif in Python). The first form if-if-if tests all conditions, whereas the second if-elif...
5493 sym R (5821 sym/79 pcs)
Lesson 7 - Nested Loops Part 2
Lesson 7 | 15 April 2020 Nested Loops As a reminder, here is the general format of a nested loop: # loop (condition) { # block of instructions # loop (condition) { # block of instructions # } # } Example 1 Let’s go through last time’s example again: Picture the passing of a year… The outer loop can be considered as the start of ...
2280 sym R (4596 sym/16 pcs)
Problem Set 3 - Solutions
Problem Set 3: Solutions | 8 April 2020 - 15 April 202 at 10 AM Problem 1. Review Let’s play a game - snakes and ladders! Snakes and Ladders is an ancient Indian board game regarded today as a worldwide classic. It is played between two or more players on a board with numbered, gridded squares and populated by “ladders” and “snakes”. Th...
1014 sym R (5747 sym/8 pcs)
Problem Set 2 - Solutions
Problem Set 2 | 1 April 2020 - 8 April 202 at 10 AM Problem 11. From PSET 1 We didn’t get to this problem but go ahead and try it this time! Write an R program to convert temperatures to and from celsius, fahrenheit. You may need to look back to Lesson 3 to revisit if statements. temp = c('32C') degree = as.integer(substr(temp, 1, 2)) i_convent...
2149 sym R (2840 sym/32 pcs) 1 img
Lesson 6 - Nested Loops
Lesson 6 | 8 April 2020 Next and Break Statements in R Before we go into the concept of nested for loops, let’s go over two control-flow constructs - the break and next statements. You have already seen the break statement, but let’s revisit it the sake of practice. A break statement is used inside a loop (repeat,for,while) to stop the iter...
1433 sym R (1756 sym/11 pcs)