我使用plyr
在 data.frame 中重命名值有困难。这似乎是一个常见的问题,但other,similar Q / As并不适合我。我使用的是plyr
版本:1.8.4
如this 108点线程所述,以下代码应工作...
我必须犯一些简单的错误,但我不知道在哪里。
代码:
library(plyr)
df <-plyr::rename(df, c("mod1"="AT", "mod2"="CYP", "mod3"="OA"))
结果错误: from
中没有以下x
值:mod1,mod2,mod3
其他Q / As已经说过忽略此错误,或者使用setnames()
包中的data.table
。 setnames()
导致错误,dplyr的rename
函数也是如此。问题也绝对不是由于同时加载了dplyr
和plyr
。
来自另一个主题的解决方案似乎也没有改变任何内容:
names(df)[names(df) == 'mod1'] <- 'AT'
数据:
df <- structure(list(dose = c(0.5, 0.565608284362011, 0.639825462677876,0.723781164472726, 0.818753245381915, 0.5, 0.565608284362011,0.639825462677876, 0.723781164472726, 0.818753245381915, 0.926187236872587,0.5, 0.565608284362011, 0.639825462677876, 0.723781164472726,0.818753245381915, 0.926187236872587), p1 = c(0.0103075076812739,0.0116952370538794, 0.0132672958208565, 0.0150474513444454, 0.017062331184752,0.0103075076812739, 0.0116952370538794, 0.0132672958208565, 0.0150474513444454,0.017062331184752, 0.0193417088954045, 0.0103075076812739, 0.0116952370538794,0.0132672958208565, 0.0150474513444454, 0.017062331184752, 0.0193417088954045), pmin1 = c(0.00536333319279742, 0.00625496575175793, 0.00728840578671532,0.00848520965537471, 0.00987000073136779, 0.00536333319279742,0.00625496575175793, 0.00728840578671532, 0.00848520965537471,0.00987000073136779, 0.0114708496853662, 0.00536333319279742,0.00625496575175793, 0.00728840578671532, 0.00848520965537471,0.00987000073136779, 0.0114708496853662), pmax1 = c(0.0152516821697505,0.0171355083560008, 0.0192461858549976, 0.0216096930335161, 0.0242546616381362,0.0152516821697505, 0.0171355083560008, 0.0192461858549976, 0.0216096930335161,0.0242546616381362, 0.0272125681054427, 0.0152516821697505, 0.0171355083560008,0.0192461858549976, 0.0216096930335161, 0.0242546616381362, 0.0272125681054427), model = c("mod1", "mod1", "mod1", "mod1", "mod1", "mod2","mod2", "mod2", "mod2", "mod2", "mod2", "mod3", "mod3", "mod3","mod3", "mod3", "mod3")), .Names = c("dose", "p1", "pmin1", "pmax1","model"), row.names = c(1L, 2L, 3L, 4L, 5L, 101L, 102L, 103L,104L, 105L, 106L, 201L, 202L, 203L, 204L, 205L, 206L), class = "data.frame")
这对我来说非常奇怪,因为我相信这段代码以前适合我!