Chapter 2 | Exercise 4
Create a data set Linguists in a spreadsheet with the information shown in Table 2.1 and import it in R as a data frame. Mind the spaces!
Last name | First name | Framework | Born | Died |
---|---|---|---|---|
de Saussure | Ferdinand | Structuralism | 1857 | 1913 |
Chomsky | Noam | Generative Linguistics | 1928 | NA |
Lakoff | George | Cognitive Linguistics | 1941 | NA |
Create an Excel spreadsheet with the information from the table. Save the file as a text (Tab delimited) file or as a comma-separated .csv file. Next, read the table in R. For a tab-delimited file, the code is as follows:
> linguists <- read.table("Your/Path/linguists.txt", header = TRUE, sep = "\t")
> linguists
Last.name First.name Framework Born Died
1 de Saussure Ferdinand Structuralism 1857 1913
2 Chomsky Noam Generative Linguistics 1928 NA
3 Lakoff George Cognitive Linguistics 1941 NA
If you saved the data as a comma-separated file (.csv) and the separator is comma, the code is as follows:
> linguists <- read.csv("Your/Path/linguists.csv")
> linguists
[output omitted]
In case the separator is the semicolon, use read.csv2()
:
> linguists <- read.csv2("Your/Path/linguists.csv")
Note that in the .csv cases, the default option is header = TRUE
.