The factor levels in your data.frame should also contain the values ββin your "Cat" object for the corresponding factor column.
Here is a simple example:
df <- data.frame(v1 = c("a", "b"), v2 = 1:2) toAdd <- list("c", 3)
Alternatively, consider the rbindlist from "data.table", which should save you from having to convert factor levels:
> library(data.table) > df <- data.frame(v1 = c("a", "b"), v2 = 1:2) > rbindlist(list(df, toAdd)) v1 v2 1: a 1 2: b 2 3: c 3 > str(.Last.value) Classes 'data.table' and 'data.frame': 3 obs. of 2 variables: $ v1: Factor w/ 3 levels "a","b","c": 1 2 3 $ v2: num 1 2 3 - attr(*, ".internal.selfref")=<externalptr>
source share