I like plyr's renaming function rename
. I have recently started using dplyr, and was wondering if there is an easy way to rename variables using a function from dplyr, that is as easy to use as to plyr's rename
?
相关问题
- R - Quantstart: Testing Strategy on Multiple Equit
- Using predict with svyglm
- Reshape matrix by rows
- Extract P-Values from Dunnett Test into a Table by
- split data frame into two by column value [duplica
相关文章
- How to convert summary output to a data frame?
- How to plot smoother curves in R
- Paste all possible diagonals of an n*n matrix or d
- ess-rdired: I get this error “no ESS process is as
- How to use doMC under Windows or alternative paral
- dyLimit for limited time in Dygraphs
- Saving state of Shiny app to be restored later
- How to insert pictures into each individual bar in
It is not listed as a function in dplyr (yet): http://cran.rstudio.org/web/packages/dplyr/dplyr.pdf
The function below works (almost) the same if you don't want to load both plyr and dplyr
Edit: The comment by Romain produces the following (note that the changes function requires dplyr .1.1)
dplyr version 0.3 added a new
rename()
function that works just likeplyr::rename()
.The next version of dplyr will support an improved version of select:
You can actually use
plyr
'srename
function as part ofdplyr
chains. I think every function that a) takes adata.frame
as the first argument and b) returns adata.frame
works for chaining. Here is an example:UPDATE: The current version of
dplyr
supports renaming directly as part of theselect
function (see Romain Francois post above). The general statement about using non-dplyr functions as part ofdplyr
chains is still valid though andrename
is an interesting example.While not exactly renaming,
dplyr::select_all()
can be used to reformat column names. This example replaces spaces and periods with an underscore and converts everything to lower case:I tried to use dplyr::rename and I get an error:
I instead used the base R function which turns out to be quite simple and effective: