环境配置相关操作

徐锋 / 2021-04-24

Email: xufeng34@163.com


  1. 数据框中因子与字符串互转:
    • 因子转字符
      df<-data.frame(Gender = c("F", "F", "M","M","F"), 
                     Score  = c(80, 70, 65, 85, 95),
                     Type = c("A","B","C","B","B"))
      df[sapply(df, is.character)] <- lapply(df[sapply(df, is.character)], 
                                             as.factor)
    • 字符转因子
      df[sapply(df, is.factor)] <- lapply(df[sapply(df, is.factor)], 
                                             as.character)
  2. 关闭、打开警告:
    options(warn = -1) #关闭警告信息
    options(warn = 0) #打开警告信息