man*_*ani 6 indexing r dataframe matrix-indexing
我是R的新手,有时会遇到代码.我遇到了以下代码之一.-7在下面的代码中意味着什么?
round(cor(longley[,-7]),3)
Run Code Online (Sandbox Code Playgroud)
我理解:舍入为舍入,longley为data.frame,3:舍入为数字,但不为-7.
Rei*_*son 13
在上下文中,[, -7]它意味着7从数据框中删除第一列longley(或者除了7从中获取所有列longley).
这是R 101,您可以阅读一些介绍性材料.例如,这在R附带的"R 简介"手册中很早就已经涵盖,或者可以从R网站访问.或者你可以阅读?Extract.
这是一个例子
> head(longley)
GNP.deflator GNP Unemployed Armed.Forces Population Year Employed
1947 83.0 234.289 235.6 159.0 107.608 1947 60.323
1948 88.5 259.426 232.5 145.6 108.632 1948 61.122
1949 88.2 258.054 368.2 161.6 109.773 1949 60.171
1950 89.5 284.599 335.1 165.0 110.929 1950 61.187
1951 96.2 328.975 209.9 309.9 112.075 1951 63.221
1952 98.1 346.999 193.2 359.4 113.270 1952 63.639
> names(longley)
[1] "GNP.deflator" "GNP" "Unemployed" "Armed.Forces" "Population"
[6] "Year" "Employed"
> names(longley)[7]
[1] "Employed"
> head(longley[, -7])
GNP.deflator GNP Unemployed Armed.Forces Population Year
1947 83.0 234.289 235.6 159.0 107.608 1947
1948 88.5 259.426 232.5 145.6 108.632 1948
1949 88.2 258.054 368.2 161.6 109.773 1949
1950 89.5 284.599 335.1 165.0 110.929 1950
1951 96.2 328.975 209.9 309.9 112.075 1951
1952 98.1 346.999 193.2 359.4 113.270 1952
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10845 次 |
| 最近记录: |