本文介绍了读取Excel文件时R中stringAsFactors中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道'R'中stringsAsFactors的任何替代方法,我知道这在'R'studio中的CSV和XLSX中有效,但在'R'中stringsAsFactors不适用于读取XLSX文件.

I wanted to know is there any alternative for stringsAsFactors in 'R', I know this works in CSV and XLSX in 'R' studio, but in 'R' stringsAsFactors is not working for reading XLSX file.

Sheet3_5K=read.xlsx("Latest Write off Sheet.xlsx",sheet = "£3-5K",stringsAsFactors = F)
Error in read.xlsx("Latest Write off Sheet.xlsx", sheet = "£3-5K", stringsAsFactors = F) : 
  unused argument (stringsAsFactors = F)

我的结果是不要让'R'从chr成为因数,而是希望chr保持为相同的chr变量

My outcome is to refrain 'R' to make factor from chr,and instead want chr to remain as same chr variable

任何帮助将不胜感激!

推荐答案

您可以使用xlsx包中的read.xlsx()函数.它将分类字符变量作为因子读取.

You may use read.xlsx() function from xlsx package.It reads categorical character variables as factors.

这是相同的代码:

install.packages("xlsx")
library(xlsx)
Data = read.xlsx(filename, 1, header=TRUE, startRow=1)

这篇关于读取Excel文件时R中stringAsFactors中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 19:41