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

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.

主站蜘蛛池模板: 天祝| 靖宇县| 漳浦县| 临清市| 同德县| 临颍县| 金平| 浦东新区| 广元市| 南岸区| 辉南县| 嘉定区| 洛阳市| 涪陵区| 布尔津县| 神池县| 鹤壁市| 常宁市| 长阳| 于都县| 那曲县| 英吉沙县| 当雄县| 田林县| 霞浦县| 佛山市| 屏山县| 鄱阳县| 青浦区| 西青区| 新巴尔虎左旗| 鸡泽县| 康乐县| 盐源县| 济源市| 建平县| 罗平县| 定陶县| 朝阳县| 公安县| 北京市|