Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- calculate_brothers <- function(brothers_list) {
- lt <- 0 #less than two
- et <- 0 #equals two
- mt <- 0 #more than two
- for(i in 1:10) {
- if(brothers_list[i] < 2) {
- lt <- lt+1
- }
- else if(brothers_list[i] > 2) {
- mt <- mt+1
- }
- else {
- et <- et+1
- }
- }
- result <- c(lt,et,mt)
- return(result)
- }
- number_of_brothers <- c(1, 2, 5, 2, 3, 1, 0, 3, 0, 1)
- numbers <- calculate_brothers(number_of_brothers)
- sprintf("You have %d people with less than 2 brothers, %d with more than 2, and %d with 2", numbers[1], numbers[2], numbers[3])
- # barplot(numbers) #use it, if you want to see the graphic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement