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

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.

主站蜘蛛池模板: 胶州市| 房产| 蚌埠市| 岳普湖县| 潢川县| 德格县| 日喀则市| 南涧| 滦平县| 丰城市| 颍上县| 博爱县| 丰城市| 盐边县| 辉南县| 彭泽县| 黑龙江省| 邓州市| 晋江市| 阿巴嘎旗| 环江| 县级市| 万山特区| 古丈县| 九台市| 桃园市| 新兴县| 邹城市| 滦平县| 苍梧县| 固始县| 神木县| 启东市| 疏勒县| 仪征市| 毕节市| 兴和县| 深圳市| 麦盖提县| 探索| 焉耆|