Solution Review: Data Frames

In this review, we give a detailed analysis of the solution to this problem.

Solution: Using data.frame()

Press + to interact
Course <- c("Maths", "English", "Science")
LecturesTaken <- c("12", "49", "52")
Grade <- c('F', 'B', 'A')
studentDataframe <- data.frame(Course, LecturesTaken, Grade)
print(studentDataframe)

Explanation

The solution to this exercise is simple. We first create vectors of Course, LecturesTaken, and Grade, according to the given data. Later we pass the three vectors to data.frame() and simply print it.

Note: We cannot use cat() here because cat() takes objects that contain data of only one type. But a data frame for example in this exercise contains data of multiple types: character, integer, etc. This is why we use only print() here.