Im getting an error when trying to sort my data frame by the model_AIC column
data <- structure(list(model_ID = list(model_table = character(0), model_info_2 = "S_M ~ 1 average_Ca_LOG (1 average_Ca_LOG | ID)",
model_info_2 = "S_M ~ 1 average_Mg_LOG (1 average_Mg_LOG | ID)",
model_info_2 = "S_M ~ 1 average_K_LOG (1 average_K_LOG | ID)",
model_info_2 = "S_M ~ 1 average_Mn_LOG (1 average_Mn_LOG | ID)",
model_info_2 = "S_M ~ 1 average_Cu_LOG (1 average_Cu_LOG | ID)",
model_info_2 = "S_M ~ 1 average_Zn_LOG (1 average_Zn_LOG | ID)"),
model_AIC = list(model_table = numeric(0), model_info_2 = "1504.62",
model_info_2 = "1636.35", model_info_2 = "1620", model_info_2 = "1407.41",
model_info_2 = "1855.04", model_info_2 = "1706.71"),
model_BIC = list(model_table = numeric(0), model_info_2 = "1531.06251699724",
model_info_2 = "1662.78856677628", model_info_2 = "1646.44040865957",
model_info_2 = "1433.85260732148", model_info_2 = "1881.47787878473",
model_info_2 = "1733.15601219833")), class = "data.frame", row.names = c("model_table",
"model_info_2", "model_info_2.1", "model_info_2.2", "model_info_2.3",
"model_info_2.4", "model_info_2.5"))
data[order(-data$model_AIC),][1:5,]
error Error in -data$model_AIC : invalid argument to unary operator
CodePudding user response:
You can try with tidyverse. The code will be easier to read. For example
library(tidyverse)
data %>%
mutate(model_AIC_int = as.integer(model_AIC)) %>%
arrange(desc(model_AIC_int))
# or just
data %>%
arrange(desc(as.integer(model_AIC)))