r - dplyr rename not working with regular expression -


the select function works fine when try rename variables according conditions

require(dplyr) select(iris, petal = starts_with("petal")) 

however when try keep other variables using

rename(iris, petal = starts_with("petal"))  error: arguments rename must unquoted variable names. arguments petal not. 

i have no idea why dplyr complains this. if behavior intended, right way rename variables using starts_with (or contains) while keeping other variables there?

select renaming them you. can add everything() call in order rest of columns

select(iris, petal = starts_with("petal"), everything()) #     petal1 petal2 sepal.length sepal.width    species # 1      1.4    0.2          5.1         3.5     setosa # 2      1.4    0.2          4.9         3.0     setosa # 3      1.3    0.2          4.7         3.2     setosa # 4      1.5    0.2          4.6         3.1     setosa # 5      1.4    0.2          5.0         3.6     setosa # 6      1.7    0.4          5.4         3.9     setosa # 7      1.4    0.3          4.6         3.4     setosa # 8      1.5    0.2          5.0         3.4     setosa # 9      1.4    0.2          4.4         2.9     setosa ... 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -