[英]Maintain Original Column Names with XLConnect readWorksheet in R
I am reading in the column header from a .xlsx
file using XLConnect::readWorksheet
. 我正在使用
XLConnect::readWorksheet
从.xlsx
文件中读取列标题。 The issue is that the column header contains /
and spaces
between words, which are replaced with .
问题是列标题包含
/
和单词之间的spaces
,并用代替.
by the package when loading. 装箱时按包装。
For example, an Excel spreadsheet with header First Name
and Sex/Gender
will appear in R as First.Name
and Sex.Gender
. 例如,具有标题
First Name
和Sex/Gender
的Excel电子表格将在R中显示为First.Name
和Sex.Gender
。
This is a problem, because I don't know if .
这是一个问题,因为我不知道是否
.
represents a /
or a space
. 代表一个
/
或一个space
。
Is there a way to override this feature and simulate data.table
functionality where column names are maintained and wrapped in a ` (backtick)? 有没有办法重写此功能并模拟
data.table
功能,其中的列名称被维护并包装在`(反引号)中?
There is an argument of check.names, with a default value of TRUE, if you change it to FALSE, then the column names will be maintained. 有一个check.names参数,默认值为TRUE,如果将其更改为FALSE,则将保留列名称。
XLConnect::readWorksheet(loadWorkbook("C:/Book1.xlsx"), sheet = 1, check.names = FALSE)
You may also want to use the readxl packages as in the example: 您可能还需要使用readxl软件包,如示例所示:
readxl::read_excel("C:/Book1.xlsx")
This doesn't have an option for check.names or similar, but the default behavior does not change the column names. 它没有check.names或类似选项,但是默认行为不会更改列名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.