我有一个数据帧列是因素的情况。
levels(df$col1)
将使我得到的级别包含双引号。
> levels(risk_register_data$Division)
[1] "Commercial" "Group Finance"
> as.character(levels(risk_register_data$Division))
[1] "Commercial" "Group Finance"
> csv_char <- as.character(levels(risk_register_data$Division))
> csv_char
[1] "Commercial" "Group Finance"
> paste("Levels are: ", csv_char)
[1] "Levels are: Commercial" "Levels are: Group Finance"
我想要以这种方式输出,以便可以将其用作ggplot的标题,注释或文本:
> csv_char
> [1] "Levels are: Commercial, Group Finance"
任何建议,如何完成?