2016-05-11 19 views

回答

2

?select尋找到everything引用,他們必須重新排序列的例子使用:

# Reorder variables: keep the variable "Species" in the front 
select(iris, Species, everything()) 

在這種情況下,Species列移到第一列,所有列被保留,並沒有列複製。

也可能存在其他用例。

0

又如用例:

# Moves the variable Petal.Length to the end 
select(iris, -Petal.Length, everything()) 

(我是在這裏看到:https://stackoverflow.com/a/30472217/4663008

無論哪種方式,格雷戈爾的回答和我混淆了我 - 我本來期望物種在格里高爾的複製示例或在我的示例中刪除。

如果你嘗試一些更復雜的基於以上兩個例子,這是行不通的:

> dplyr::select(iris, Petal.Width, -Petal.Length, everything()) 
    Petal.Width Sepal.Length Sepal.Width Petal.Length Species 
1   0.2   5.1   3.5   1.4  setosa 
2   0.2   4.9   3.0   1.4  setosa 
3   0.2   4.7   3.2   1.3  setosa 

編輯: 快速response後從GitHub上哈德利,我發現有一個特殊的使用everything()與select()中第一個位置的負數相結合的行爲將使用所有變量開始select(),然後everything()將它們再次取出。非首要職位的負面變量並不像預期的那樣有效。

我同意,在第一位置和一切()select_helper功能的負面變量必須在文檔中更好地解釋

編輯2:文檔現在已經更新到狀態「正值選擇變量;負如果第一個表達式爲負數,select()將自動以所有變量開始。「