Error type
Error: All arguments must be named
The use of rename in plyr is different from that in dplyr.
plyr::rename
rename(data, c(old=new))
dplyr::rename
rename(data, new = old)
Example
For example, the default is plyr’s rename. Run the following command, and an error will be reported :
d <- data.frame(old1=1:3, old2=4:6, old3=7:9)
d
library(tidyverse)
rename(d, c("old2"="two", "old3"="three"))
rename(d, c(old2="two", old3="three"))
p>
result
> d <- data.frame(old1=1:3, old2=4:6, old3=7:9)
> d
old1 old2 old3
1 1 4 7
2 2 5 8
3 3 6 9
> library(tidyverse)
> rename(d, c("old2"="two", "old3"="three"))
Error: All arguments must be named
> rename(d, c(old2="two", old3="three"))
Error: All arguments must be named
:
d <- data.frame(old1=1:3, old2=4:6, old3=7:9)
d
rename(d, two=old2, three=old3)
result: p>
> d <- data.frame(old1=1:3, old2=4:6, old3=7:9)
> d
old1 old2 old3
1 1 4 7
2 2 5 8
3 3 6 9
> rename(d, two=old2, three=old3)
old1 two three
1 1 4 7
2 2 5 8
3 3 6 9
Either
or with plyr modified in the first way :
d <- data.frame(old1=1:3, old2=4:6, old3=7:9)
d
library(tidyverse)
plyr::rename(d, c("old2"="two", "old3"="three"))
plyr::rename(d, c(old2="two", old3="three"))
result: p>
> d <- data.frame(old1=1:3, old2=4:6, old3=7:9)
> d
old1 old2 old3
1 1 4 7
2 2 5 8
3 3 6 9
> library(tidyverse)
> plyr::rename(d, c("old2"="two", "old3"="three"))
old1 two three
1 1 4 7
2 2 5 8
3 3 6 9
> plyr::rename(d, c(old2="two", old3="three"))
old1 two three
1 1 4 7
2 2 5 8
3 3 6 9
done!!!!!!
key points, dplyr is the new name in front, the old name is placed behind, and without quotes, not c(), more convenient!!
In addition, the select in dplyr can also select + the name, directly specifying the number of columns!!
d <- data.frame(old1=1:3, old2=4:6, old3=7:9)
d
select(d,one=1,three=3)
result: p>
> d <- data.frame(old1=1:3, old2=4:6, old3=7:9)
> d
old1 old2 old3
1 1 4 7
2 2 5 8
3 3 6 9
> select(d,one=1,three=3)
one three
1 1 7
2 2 8
3 3 9
div>
Read More:
- Error analysis of multiple linear regression in R language model.frame.default
- R language error error: n() should only be called in a data context
- Usage and examples of three important functions of tidyr package in R language: gather, spread and separate
- The solution of “error in NLS loop more than 50” in R language
- R-DataCamp-Data Manipulation with dplyr in R
- R language error in match.names (clabs, names(xi)) :
- R language error in hist.default ():’x’must be a value
- Solving the problem of saving object set by save() function in R language
- Trivia: How does R language solve Error in ts(x):’ts’ object must have one or more observations
- R language error messages and related solutions
- R language-Error in file(out, “wt”): Unable to open the link problem solved
- 13. R language: Error in match.names(clabs, names(xi)): The name is not relative to the original name
- R language notes – sample() function
- Word column after the text evenly distributed in the left and right two columns, rather than fill in the left column and then fill in the right column, how to do?
- R note for Bioinfo: the column for the select call is undefined
- In R language, for loop or array truncation, the following error occurs only 0’s may be mixed with negative subscripts
- Installation and use of R language ggmap package
- ArcGIS publishing service analysis report error unresolved 00002 data frame has no space reference
- R language – path setting and working directory modification
- Solutions to the failure of R language loading rjava