Instructions

Complete the following exercises in this R Markdown document. For each question, write your code in the provided code chunks and answer any written questions in complete sentences. Knit your document to HTML when finished and submit both the .Rmd and .HTML files.

Total Points: 6


Question 1: Data Import and Initial Exploration (1 point)

Download the file enlightenment_thinkers.csv from the course website and save it to your working directory. This dataset contains information about major Enlightenment philosophers, including their birth and death years, nationality, major works, and whether they lived to see the French Revolution (which began in 1789).

a) Import the CSV file into R and store it as an object called thinkers. Display the structure of the dataset.

# Your code here

b) Based on the data structure, how many philosophers are in the dataset? How many variables does it contain?

Your answer here


Question 2: Sorting Data (1.5 points)

a) Sort the thinkers dataset by birth year (the Birth column) in ascending order and display all rows. Using R, display data from philosopher born first.

# Your code here

b) Sort the dataset first by Nationality (ascending alphabetically) and then by Death year (descending). Display the first 8 rows of the sorted dataset.

# Your code here

c) Identify the philosopher who lived the longest (i.e., the largest difference between Death and Birth). Display their full row of data.

# Your code here

Question 3: Subsetting with Logical Conditions (2 points)

a) Create a subset of the thinkers dataset containing only French philosophers. How many French philosophers are in the dataset?

# Your code here

b) Create a subset of philosophers who lived to see the French Revolution (where Saw_Revolution equals TRUE). Display all rows of this subset.

# Your code here

c) Create a subset of philosophers who were born after 1720 AND died before 1800. How many meet both criteria?

# Your code here

d) Create a subset of philosophers who were either British OR German. Display the first 5 rows of this subset.

# Your code here

Question 4: Combining Subsetting and Sorting (1 point)

a) Create a subset of the thinkers dataset containing only philosophers born after 1700, then sort this subset by death year in ascending order. Display the first 4 rows.

# Your code here

b) Calculate the lifespan of each philosopher in the dataset (Death minus Birth), add it as a new column called Lifespan, then sort the entire dataset by Lifespan in descending order. Who lived the longest?

# Your code here

Your answer here (who lived longest):


Question 5: Data Export (0.5 points)

a) Export your modified thinkers dataset (the one with the Lifespan column added) to a new CSV file called “thinkers_with_lifespan.csv”. Make sure to include row names in the export.

# Your code here

b) In 1-2 sentences, explain what would happen if you set row.names = FALSE when exporting to CSV. It’s certainly OK to check the help pages.

Your answer here


Session Info (Do not modify)

This gives us info on the types of operating systems, R versions, and packages y’all are using in the class. If you’d prefer not to share, that’s totally fine! Just omit the sessionInfo() line below.

sessionInfo()