Exercise

This exercise will combine new learning from Week 2 with what we learned in Week 1. Using if else and for use the following matrix to print an ASCII R in the console. hint: combine characters with paste0.

r_chr_matrix <- structure(c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, 
TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, 
TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, 
FALSE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, 
TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, 
FALSE, TRUE), .Dim = c(7L, 10L))

The output should look something like this. Feel free to substitute the "*" and " " with whatever you prefer.

[1] " ******** "
[1] " **     **"
[1] " **     **"
[1] " ******** "
[1] " **   **  "
[1] " **    ** "
[1] " **     **"

For bonus points, write a function that will allow a user to specify which character for TRUE and which character for FALSE. See ASCII generator for inspiration.

Links

Matthew Ray

Matthew is a tech news enthusiast. He spends most of his time reading tech focused news, watching sports and drinking coffee. You will probably find him at a coffee shop or the library.

  1. Comments for Week 2 Links and Exercise

You May Also Like