I am having difficulty renaming values in a data.frame using plyr
. This appears to be a somewhat common problem, but other, similar Q/As aren't working for me. I am using plyr
version: 1.8.4
As noted in this 108 point thread, the following code should work...
I must be making some simple error, but I don't know where.
Code:
library(plyr)
df <-plyr::rename(df, c("mod1"="AT", "mod2"="CYP", "mod3"="OA"))
resulting error: The following from
values were not present in x
: mod1, mod2, mod3
Other Q/As have said to disregard this error, or to use setnames()
from the data.table
package. setnames()
results in an error, as does dplyr's rename
function. The issue is also definitely not due to loading both dplyr
and plyr
.
This solution from the another thread also doesn't appear to change anything:
names(df)[names(df) == 'mod1'] <- 'AT'
data:
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")
This is incredibly strange for me, because I believe this code was previously working for me!