Solution Review: Data Frames
Explore how to construct data frames in R by combining vectors of different data types using the data.frame function. Understand the importance of using print over cat when displaying data frames to correctly output mixed data types.
We'll cover the following...
We'll cover the following...
Solution: Using data.frame()
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 becausecat()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 onlyprint()here.