Name:
Andrew ID:
Collaborated with:
This lab is to be completed in class. You can collaborate with your classmates, but you must identify their names above, and you must submit your own lab as an Rmd file on Blackboard, by 11:59pm on the day of the lab.
Make a string with your last name, and (programmatically) count the number of characters.
Make a vector of strings of length 2, with your first name and then last name, and count the number of characters in each.
Transform your the vector in the last question so that the words have all uppercase chars.
Make a string with “Regards,” and then your first name, separated by a newline character. Print it to the console.
Count the number of characters in the string in the last question. Is the comma counted? The newline counted?
Make a vector of strings with the numbers 1 through 20.
Make a matrix that is 2 x 2. Fill the first column with your first and last name. Fill the second column with the first and last name of your favorite statistician. Display the matrix.
Flip the order of entries in the second column of the matrix in the last question, in just one line of code. Display the matrix.
Run the commands matrix(as.character(1:16), 4, 4)
and as.character(matrix(1:16), 4, 4)
, and explain the difference.
Convert the matrix mat = matrix(as.character(1:16), 4, 4)
into a matrix of numbers, using as few lines of code as possible.
Explain what is going on with the conversions below.
nchar(1:5)
## [1] 1 1 1 1 1
nchar(1e5)
## [1] 5
my.str
. Then run the code below and try to explain what each step is doing. We will learn these commands in detail next week, for now, you can just make a guess.my.str = "My string goes here"
nchar(my.str)
## [1] 19
my.list = strsplit(my.str, split="")
my.chars = my.list[[1]]
head(my.chars, 20)
## [1] "M" "y" " " "s" "t" "r" "i" "n" "g" " " "g" "o" "e" "s" " " "h" "e"
## [18] "r" "e"
length(my.chars)
## [1] 19
my.chartab = table(my.chars)
my.chartab
## my.chars
## e g h i M n o r s t y
## 3 3 2 1 1 1 1 1 2 2 1 1
plot(my.chartab, xlab="Characters", ylab="Counts")