报错类型
Error: All arguments must be named
plyr中的rename和dplyr中的rename用法是不同的.
rename(data, c(old=new))
rename(data, new = old)
比如, 默认的是plyr的rename, 运行下面命令, 会报错:
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"))
结果
> 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)
结果:
> 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
或者使用plyr按第一种方式修改:
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"))
结果:
> 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
搞定!!!
d <- data.frame(old1=1:3, old2=4:6, old3=7:9)
d
select(d,one=1,three=3)
结果:
> 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