Как извлечь значения из data.table на основе нескольких условий?
Мне нужна функция, которая возвращает значение столбца data.table на основе двух других значений столбца:
require(data.table)
dt <- data.table(
"base" = c("of", "of", "of", "lead and background vocals", "save thou me from", "silent in the face"),
"prediction" = c("the", "set", "course", "from", "the", "of"),
"count" = c(258586, 246646, 137533, 4, 4, 4)
)
> dt
# base prediction count
#1: of the 258586
#2: of set 246646
#3: of course 137533
#4: lead and background vocals from 4
#5: save thou me from the 4
#6: silent in the face of 4
# the function needs to return the "prediction" value based on the max "count" value for the input "base" value.
# giving the input "of" to function:
> prediction("of")
# the desired output is:
> "the"
# or:
> prediction("save thou me from")
> "the"