- Modern R Programming Cookbook
- Jaynal Abedin
- 150字
- 2021-07-08 09:48:35
How it works…
The conversion from a matrix to a data frame works simply by assigning column names and then assigning the class property as data.frame. Since a matrix only contains one data type, the resultant data frame also contains only one data type.
The conversion of a data frame to a matrix with heterogeneous data types works a bit differently. First, it converts all columns into higher and more general data types as follows:
- A combination of character and any other data type produces a character vector
- A combination of numeric and logical data type produces a numeric vector
- A combination of complex and numeric or logical data type produces a complex vector
Then, it keeps only one type of data because a matrix is restricted to only one data type. Also, during the conversion, it preserves the column names, which can be accessed by the colnames() function.
推薦閱讀
- TypeScript入門與實戰
- UML和模式應用(原書第3版)
- Spring 5.0 By Example
- DevOps with Kubernetes
- ReSharper Essentials
- Python機器學習:數據分析與評分卡建模(微課版)
- Java程序員面試算法寶典
- Functional Programming in JavaScript
- C/C++常用算法手冊(第3版)
- Python神經網絡項目實戰
- iOS自動化測試實戰:基于Appium、Python與Pytest
- Android驅動開發權威指南
- IDA Pro權威指南(第2版)
- HTML5+CSS3+JavaScript 從入門到項目實踐(超值版)
- QlikView Unlocked