使用plyr

时间:2016-11-22 00:11:26

标签: r plyr

我使用plyr data.frame 重命名值有困难。这似乎是一个常见的问题,但othersimilar 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.tablesetnames()导致错误,dplyr的rename函数也是如此。问题也绝对不是由于同时加载了dplyrplyr

来自另一个主题的解决方案似乎也没有改变任何内容:

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")

这对我来说非常奇怪,因为我相信这段代码以前适合我!

0 个答案:

没有答案