---
title: "Ling 201, session 02: R basics (class)"
author:
   - name: "[Stefan Th. Gries](https://www.stgries.info)"
     affiliation: "UC Santa Barbara & JLU Giessen"
     orcid: 0000-0002-6497-3958
date: "2027-01-12 12:34:56"
date-format: "DD MMM YYYY HH-mm-ss"
editor: source
format:
   html:
      page-layout: full
      code-fold: true
      code-link: true
      code-copy: true
      code-tools: true
      code-line-numbers: true
      code-overflow: scroll
      number-sections: true
      smooth-scroll: true
      toc: true
      toc-depth: 4
      number-depth: 4
      toc-location: left
      monofont: lucida console
      tbl-cap-location: top
      fig-cap-location: bottom
      fig-width: 6
      fig-height: 6
      fig-format: png
      fig-dpi: 300
      fig-align: center
      embed-resources: true
      include-in-header:
         text: '<link rel="shortcut icon" href="https://www.stgries.info/favicon.ico" type="image/x-icon" />'
execute:
   cache: false
   echo: true
   eval: true
   warning: false
---

```{r prepworkspace}
rm(list=ls(all=TRUE)); library(magrittr)
```

# Exercise 01

Generate a data frame `abc` that contains the letters from "a" to "j" in the first column and the integers from 10 to 1 in the second column. Make sure the first column is called "LETTER" and the second "NUMBER" and that columns with categorical variables are factors.

```{r exercise01}
# replace this with your answer/code
```

# Exercise 02

Load the text file [_input/dataframe1.csv](_input/dataframe1.csv) into a data frame `example` such that the first row is recognized as containing the column names.

```{r exercise02}
# replace this with your answer/code
```

# Exercise 03

Extract from this data frame `example`

a. the second and third column;

```{r exercise03a}
# replace this with your answer/code
```

b. the third and fourth row.

```{r exercise03b}
# replace this with your answer/code
```

# Exercise 04

Split the data frame `example` up according to the content of the second column (enter `?split` at the R prompt for help) and call the result `example.split`.

```{r exercise04}
# replace this with your answer/code
```

# Exercise 05

Change the value at the intersection of the third row and the fourth column into "indef" and save the changed data frame into [_output/dataframe2.csv](_output/dataframe2.csv) such that you can easily load/edit in a spreadsheet software.

```{r exercise05}
# replace this with your answer/code
```

# Exercise 06

Generate the following data frame and call it `EPP` (for English personal pronouns):

| PRONOUN | PERSON | NUMBER |
|:-------:|:------:|:------:|
| I       | 1      | sg     |
| you     | 2      | sg     |
| he      | 3      | sg     |
| she     | 3      | sg     |
| it      | 3      | sg     |
| we      | 1      | pl     |
| you     | 2      | pl     |
| they    | 3      | pl     |

```{r exercise06}
# replace this with your answer/code
```

# Exercise 07

Extract from this data frame

a. the value of the 4th row and the 2nd column;

```{r exercise07a}
# replace this with your answer/code
```

b. the values of the 3rd to 4th rows and the 1st to 2nd columns;

```{r exercise07b}
# replace this with your answer/code
```

c. the rows that have plural pronouns in them;

```{r exercise07c}
# replace this with your answer/code
```

d. the rows with 1st and 3rd person pronouns.

```{r exercise07d}
# replace this with your answer/code
```

# Exercise 08

Generate a vector `FREQS` of the frequencies with which the personal pronouns in `EPP` occurred in a small corpus: I: 8426, you: 9462, he: 6394, she: 4234, it: 6040, we: 2305, you: 8078, they: 2998. Then, make this vector the fourth column of `EPP`.

```{r exercise08}
# replace this with your answer/code
```

# Exercise 09

Save the data frame into [_output/dataframe3.csv](_output/dataframe3.csv) such that you can easily load/edit in a spreadsheet software.

```{r exercise09}
# replace this with your answer/code
```

# Exercise 10

The file [_input/dataframe4.csv](_input/dataframe4.csv) contains data for the VERB *into* VERB*ing* construction in the BNC (e.g., He [~V1~ forced] him into [~V2~ speaking] about it). For each instance of one such construction, the file contains

* a column called `BNC`: the file where the instance was found (A06 in the first case);
* a column called `VERB_LEMMA`: the lemma of the finite verb (*force*);
* a column called `ING_FORM`: the gerund (*speaking*);
* a column called `ING_LEMMA`: the lemma of the gerund (*speak*);
* a column called `ING_TAG`: the part-of-speech tag of the gerund (VVG in the first case).

Load this file into a data frame `COV` and display the first six rows of `COV`. Correct the typo in line 3 (use *take*).

```{r exercise10}
# replace this with your answer/code
```

# Exercise 11

What

a. is the quickest way of identifying the numbers of verb lemma types and -*ing* lemma types?

```{r exercise11a}
# replace this with your answer/code
```

b. is the most frequent verb lemma?

```{r exercise11b}
# replace this with your answer/code
```

c. is the most frequent -*ing* lemma with this verb lemma?

```{r exercise11c}
# replace this with your answer/code
```

# Exercise 12

Changing and saving `COV`:

a. Delete the column with the corpus files; the new data frame is to be called `COV.2`.

```{r exercise12a}
# replace this with your answer/code
```

b. Delete the rows with the four rarest tags; the new data frame is to be called `COV.3`.

```{r exercise12b}
# replace this with your answer/code
```

c. From `COV.3`, create a new data frame `COV.4` which is sorted according to, first, the column `VERB_LEMMA` (ascending) and, second, the `ING_LEMMA` (descending).

```{r exercise12c}
# replace this with your answer/code
```

d. Save the changed data frame into a text file [_output/dataframe5.csv](_output/dataframe5.csv); use tab stops as separators, newlines as line breaks, and make sure you don't have row numbers and no quotes.

```{r exercise12d}
# replace this with your answer/code
```

# Session info

```{r sessionInfo}
sessionInfo()
```
