R-$和@符号的意义

R-$和@符号的意义

R语言中,

$表示从一个dataframe中取出某一列数据

@是从R的类实例里面读取数据,bg=x@colors b g . c o l x c o l o r s c o l o r s d a t a f r a m e bg.col就是从对象实例x中取出colors,而这个colors本身又是个dataframe,所以需要进一步用 读取bg.col列。

#列表,更像java中的map
e<-list(thing=“hat”,size=“8.25”)
e
$thing
[1] “hat”

$size
[1] “8.25”

e t h i n g [ 1 ] &quot; h a t &quot; e thing [1] &quot;hat&quot; e size
[1] “8.25”
e[1]
$thing
[1] “hat”

e[[1]]
[1] “hat”

str用来告诉结果的构成方式,对于不少Bioconductor的包,或者复杂的R函数的输出,都是一堆列表的嵌套,str(complex_result)会输出每个列表的名字,方便提取对应的信息。

利用str查看pca的结果,具体的PCA应用查看http://mp.weixin.qq.com/s/sRElBMkyR9rGa4TQp9KjNQ

pca_result <- prcomp(expr)
pca_result
Standard deviations:
[1] 4.769900e+00 1.790861e+00 1.072560e+00 1.578391e-01 2.752128e-16

Rotation:
PC1 PC2 PC3 PC4 PC5
Gene_a 0.99422750 -0.02965529 0.078809521 0.01444655 0.06490461
Gene_b 0.04824368 -0.44384942 -0.885305329 0.03127940 0.12619948
Gene_c 0.08258192 0.81118590 -0.451360828 0.05440417 -0.35842886
Gene_d -0.01936958 0.30237826 -0.079325524 -0.66399283 0.67897952
Gene_e -0.04460135 0.22948437 -0.002097256 0.74496081 0.62480128

str(pca_result)
List of 5
$ sdev : num [1:5] 4.77 1.79 1.07 1.58e-01 2.75e-16
$ rotation: num [1:5, 1:5] 0.9942 0.0482 0.0826 -0.0194 -0.0446 …
…- attr(, “dimnames”)=List of 2
… …$ : chr [1:5] “Gene_a” “Gene_b” “Gene_c” “Gene_d” …
… …$ : chr [1:5] “PC1” “PC2” “PC3” “PC4” …
$ center : Named num [1:5] 8 1.229 3 0.379 0.243
…- attr(
, “names”)= chr [1:5] “Gene_a” “Gene_b” “Gene_c” “Gene_d” …
$ scale : logi FALSE
$ x : num [1:5, 1:5] -6.08 1.86 3.08 5.06 -3.93 …
…- attr(*, “dimnames”)=List of 2
… …$ : chr [1:5] “A” “B” “C” “D” …
… …$ : chr [1:5] “PC1” “PC2” “PC3” “PC4” …

  • attr(*, “class”)= chr “prcomp”

取出每个主成分解释的差异

pca_result$sdev
[1] 4.769900e+00 1.790861e+00 1.072560e+00 1.578391e-01 2.752128e-16

猜你喜欢

转载自blog.csdn.net/qq_39306047/article/details/92974789