---
title: "Lab 1w: String Basics"
author: "Statistical Computing, 36-350"
date: "Wednesday August 31, 2016"
---

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.

Creating strings, counting characters
===

- 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?

Vectors, matrices, conversions
===

- 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.

```{r}
nchar(1:5) 
nchar(1e5)
```

- Find a long string of text from the web; could be a passage from a poem you like, or paragraph from a news article you like, or a couple of paragraphs. The longer the better. Copy and paste this text below (replacing the existing text), saving it as `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.

```{r}
my.str = "My string goes here"
nchar(my.str)

my.list = strsplit(my.str, split="")
my.chars = my.list[[1]]
head(my.chars, 20)
length(my.chars)

my.chartab = table(my.chars)
my.chartab
plot(my.chartab, xlab="Characters", ylab="Counts")
```