How to concatenate factors, without them being converted to integer level?

后端 未结 8 886
粉色の甜心
粉色の甜心 2020-11-28 10:12

I was surprised to see that R will coerce factors into a number when concatenating vectors. This happens even when the levels are the same. For example:

>         


        
8条回答
  •  温柔的废话
    2020-11-28 10:58

    Based on the other answers which use converting to character I'm using the following function to concatenate factors:

    concat.factor <- function(...){
      as.factor(do.call(c, lapply(list(...), as.character)))
    }
    

    You can use this function just as you would use c.

提交回复
热议问题