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

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.

主站蜘蛛池模板: 西藏| 禹城市| 融水| 府谷县| 兖州市| 花莲市| 泰顺县| 湖南省| 曲沃县| 新密市| 甘孜县| 印江| 利川市| 凤城市| 定西市| 铅山县| 游戏| 罗江县| 额敏县| 南城县| 三门县| 都匀市| 肥东县| 旬阳县| 河源市| 马鞍山市| 德化县| 佛教| 海晏县| 柘荣县| 安陆市| 大石桥市| 洞口县| 万荣县| 南宫市| 博野县| 噶尔县| 赞皇县| 鹤壁市| 鄯善县| 姚安县|