访问数据框和矩阵的一点区别-拾遗

> data[1:3,]  ##data[1:3,]与data[1:3]的不同,前者访问前三行,后者访问前三列,等同于data[,1:3]
      untrt_N61311 untrt_N052611 untrt_N080611 untrt_N061011 trt_N61311
FN1      245667.66      427435.1     221687.51      371144.2  240187.24
DCN      212953.14      360796.2     258977.30      408573.1  210002.18
CEMIP     40996.34      137783.1      53813.92       91066.8   62301.12
      trt_N052611 trt_N080611 trt_N061011
FN1      450103.2    280226.2    376518.2
DCN      316009.1    225547.4    393843.7
CEMIP    223111.9    212724.8    157919.5
> class(data)
[1] "data.frame"
> data[1:3]
           untrt_N61311 untrt_N052611 untrt_N080611
FN1         245667.6567   427435.0768   221687.5127
DCN         212953.1393   360796.2282   258977.3049
CEMIP        40996.3400   137783.0986    53813.9228
CCDC80      137229.1527   232772.1728    86258.1321
IGFBP5       77812.6548   288609.2030   210628.8654
COL1A1      146450.4130   127367.2520   152281.4983
GREM1       124246.4148   137527.2070   217280.2907
MT.RNR2      63352.8844   116052.8993   177452.3627
FTL         234852.9465   197585.0971   287309.9030
THBS1        37003.7089    51260.1710    34506.8161
......
HSPB1         7049.0643     7810.7409     6203.7621
CTSC          1658.1689     2960.0271     3329.7146
DAAM2         1643.8532     1542.1085      872.5728
 [ reached 'max' / getOption("max.print") -- omitted 26853 rows ]

 

 

但是对于矩阵

> data_t <- t(data)
> class(data_t)  ##用t()转换data之后,返回的不是data.frame。。。。没明白
[1] "matrix" "array" 
> data_t[1:3]  ##访问的是第一列的前三个数值,为何?
[1] 245667.7 427435.1 221687.5
> data_t[,1:3]  ##访问前三列
                   FN1      DCN     CEMIP
untrt_N61311  245667.7 212953.1  40996.34
untrt_N052611 427435.1 360796.2 137783.10
untrt_N080611 221687.5 258977.3  53813.92
untrt_N061011 371144.2 408573.1  91066.80
trt_N61311    240187.2 210002.2  62301.12
trt_N052611   450103.2 316009.1 223111.85
trt_N080611   280226.2 225547.4 212724.84
trt_N061011   376518.2 393843.7 157919.47

 

posted @ 2020-05-23 18:17  月光边境Eric  阅读(512)  评论(0编辑  收藏  举报