官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 房产| 巴彦淖尔市| 长泰县| 师宗县| 新干县| 宣城市| 新干县| 花垣县| 大化| 松潘县| 昆山市| 项城市| 绥阳县| 苍梧县| 郁南县| 大石桥市| 西畴县| 大厂| 古交市| 宜兴市| 定州市| 大洼县| 凉城县| 昌黎县| 读书| 渭南市| 琼结县| 定安县| 阿合奇县| 石屏县| 肥乡县| 剑阁县| 涿鹿县| 丰顺县| 泸西县| 天峻县| 交城县| 许昌县| 泗洪县| 阳新县| 新宁县|