Exercise 2: Data Structures, Variables, & Data Types

By Kristen Sosulski

Solve The Tasks In Order To Get Hands On The Concepts
What is the exercise about?

The exercise presents few tasks based on previous tutorials. Solve these 7 tasks based on the Data Structures, Variables, & Data Types. This will not only brush up your concepts but also it will give you practical exposure to R. All the best!

Task 1: Getting to know the data

a. Import the data named “winter_olympic.csv”
b. View the data
c. How many variables are in the data frame?
d. What are the name of these variables?
e. How many countries (rows) are in the data frame?

Task 2: Printing Data

a. The first row of data
b. The last row of data
c. The first 5 rows of data

Task 3: Creating Vectors

a. Create a vector called “country_medals” from the data frame
b. Create a vector called “gold” from data frame
c. What type of variable is “gold”?

Task 4: Create a new data frame that holds data from the region Asia

a. Call the data frame “asia”
b. How many rows and columns are in this data frame [Hint: use dim()]

Task 5: Create a data frame “total_medals”

a. Create vector “country”
b. Create vector “total_medal_ct”
c. Use cbind() to combine the two vectors
d. What is the type of object “total_medals”?

Task 6: Vector data counts

a. What are the different levels of data$Region? [Hint: use levels()]
b. Are any of the other variables factor variables? [Hint: use str()]

Task 7: Subsetting

a. Create a data frame that holds countries that did not win any gold medals