readNamedRegion(XLConnect)
readNamedRegion()所属R语言包:XLConnect
Reading named regions from a workbook
阅读从一个工作簿命名的区域
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Reads named regions from a workbook.
读取从workbook命名的区域。
用法----------Usage----------
## S4 method for signature 'workbook'
readNamedRegion(object, name, header, rownames, colTypes, forceConversion, dateTimeFormat, check.names)
参数----------Arguments----------
参数:object
The workbook to use
workbook使用
参数:name
The name of the named region to read
命名区域的名称来阅读
参数:header
The argument header specifies if the first row should be interpreted as column names. The default value is TRUE.
参数header指定的第一行应该被解释为列名。默认值是TRUE。
参数:rownames
Index (numeric) or name (character) of column that should be used as row names. The corresponding column will be removed from the data set. Defaults to NULL which means that no row names are applied.
指数(numeric)或名称(character)应该用作行名的列。相应的列,将被删除的的数据集。默认为NULL:这意味着没有任何行名称。
参数:colTypes
Column types to use when reading in the data. Specified as a character vector of the corresponding type names (see XLC; XLC$DATA_TYPE.<?>). You may also use R class names such as numeric, character, logical and POSIXt. The types are applied in the given order to the columns - elements are recycled if necessary. Defaults to character(0) meaning that column types are determined automatically (see the Note section for more information).<br> By default, type conversions are only applied if the specified column type is a more generic type (e.g. from Numeric to String) - otherwise NA is returned. The forceConversion flag can be set to force conversion into less generic types where possible.
在数据读取时使用的列类型。指定一个character向量的相应的类型名字(见XLC; XLC$DATA_TYPE.<?>)。您也可以使用R类的名称,如numeric,character,logical和POSIXt。在给定的顺序施加到列类型 - 被回收,如果必要的元素。默认为character(0)意义,列类型自动确定(见注部分获取更多信息)。默认情况下<BR>,类型转换只适用于指定的列类型是一个更通用的类型(例如,从数字到字符串) - 否则NA返回。 forceConversion标志可以被设置为强制转换为泛型类型在可能的情况下。
参数:forceConversion
logical specifying if conversions to less generic types should be forced. Defaults to FALSE meaning that if a column is specified to be of a certain type via the colTypes argument and a more generic type is detected in the column, then NA will be returned (example: column is specified to be DateTime but a more generic String is found). Specifying forceConversion = TRUE will try to enforce a conversion - if it succeeds the corresponding (converted) value will be returned, otherwise NA. See the Note section for some additional information.
logical指定,如果比较特殊的类型应强制转换。默认FALSE的意思,如果一列被指定为colTypes参数和检测到一个更通用的类型列中的,然后NA将返回(例如通过某种类型的:指定列的DateTime但找到一个更通用的字符串)。指定forceConversion = TRUE将尝试执行转换 - 如果成功,相应的值(转换)将被退回,否则NA。一些额外的信息,请参见注释部分。
参数:dateTimeFormat
Date/time format used when doing date/time conversions. Defaults to<br> getOption("XLConnect.dateTimeFormat"). This should be a POSIX format specifier according to strptime although not all specifications have been implemented yet - the most important ones however are available.
日期/时间格式时使用的日期/时间转换。默认为参考getOption("XLConnect.dateTimeFormat")。这应该是一个POSIX根据strptime虽然不是所有的规格已经实现 - 然而,最重要的是提供的格式说明符。
参数:check.names
logical specifying if column names of the resulting data.frame should be checked to ensure that they are syntactically valid valid variable names and are not duplicated. See the check.names argument of data.frame. Defaults to TRUE.
logical指定所产生的data.frame的列名应进行检查,以确保它们语法上是合法有效的变量名和不重复。请参阅check.namesdata.frame参数。默认为TRUE的。
Details
详细信息----------Details----------
The arguments name and header are vectorized. As such, multiple named regions can be read with one method call. If only one single named region is read, the return value is a data.frame.If multiple named regions are specified, the return value is a (named) list of data.frame's returned in the order they have been specified with the argument name.
的参数name和header量化。因此,多个命名的区域,可以读取一个方法调用。如果只有一个命名区域被读取时,返回值是一个data.frame。如果有多个命名的区域被指定,返回值是一个(命名为)list的data.frame的返回它们的顺序已被指定的参数name。
注意----------Note----------
If no specific column types (see argument colTypes) are specified, readNamedRegion tries to determine the resulting column types based on the read cell types. If different cell types are found in a specific column, the most general of those is used and mapped to the corresponding R data type. The order of data types from least to most general is Boolean (logical) < DateTime (POSIXct) < Numeric (numeric) < String (character). E.g. if a column is read that contains cells of type Boolean, Numeric and String then the resulting column in R would be character since character is the most general type.<br><br> Some additional information with respect to forcing data type conversion using forceConversion = TRUE:
如果没有特定的列类型(参数colTypes)被指定,readNamedRegion试图读的单元类型的基础上确定最终的列类型。如果不同类型的单元中被发现特定列中,那些最一般的使用,并映射到相应的R数据类型。的顺序,至少到最一般的数据类型是布尔型(logical)<日期时间(POSIXct)<数字(numeric)<字符串(character)。例如如果某列被读出的单元类型为布尔值,数字和字符串,然后将结果列在Rcharacter自character是最普遍的类型。参考参考一些额外的信息就强迫的数据类型转换使用forceConversion = TRUE:
Forcing conversion from String to Boolean: TRUE is returned if and only if the target string is "true" (ignoring any capitalization). Any other string will return FALSE.
从字符串强制转换为布尔值:TRUE返回,当且仅当目标字符串为“true”(忽略任何资本)。任何其他字符串将返回FALSE。
Forcing conversion from Numeric to DateTime: since Excel understands Dates/Times as Numerics with some additional formatting, a conversion from a Numeric to a DateTime is actually possible. Numerics in this case represent the number of days since 1900-01-01. Fractional days represent hours, minutes, and seconds.
从数字强制转换为DateTime:因为Excel理解某些附加的格式化的数值计算,从数字转换为DateTime的日期/时间实际上是可能的。 Numerics的在这种情况下,代表的天数,自1900-01-01天的小数部分表示小时,分钟和秒。
(作者)----------Author(s)----------
Martin Studer<br>
Mirai Solutions GmbH <a href="http://www.mirai-solutions.com">http://www.mirai-solutions.com</a>
参考文献----------References----------
http://www.officearticles.com/excel/named_ranges_in_microsoft_excel.htm<br> How to create named regions/ranges?<br> http://www.youtube.com/watch?v=iAE9a0uRtpM
参见----------See Also----------
workbook, readWorksheet, writeNamedRegion,<br> writeWorksheet, readNamedRegionFromFile, onErrorCell
workbook,readWorksheet,writeNamedRegion,参考writeWorksheet,readNamedRegionFromFile,onErrorCell
实例----------Examples----------
## Example 1:[#示例1:]
# mtcars xlsx file from demoFiles subfolder of package XLConnect[mtcars xlsx文件demoFiles子文件夹中的包XLConnect]
demoExcelFile <- system.file("demoFiles/mtcars.xlsx", package = "XLConnect")
# Load workbook[负载工作簿]
wb <- loadWorkbook(demoExcelFile)
# Read named region 'mtcars' (with default header = TRUE)[阅读命名区域“mtcars”(默认的头= TRUE)]
data <- readNamedRegion(wb, name = "mtcars")
## Example 2;[例2;]
# conversion xlsx file from demoFiles subfolder of package XLConnect[xlsx文件转换从demoFiles子文件夹中的包XLConnect]
excelFile <- system.file("demoFiles/conversion.xlsx", package = "XLConnect")
# Load workbook[负载工作簿]
wb <- loadWorkbook(excelFile)
# Read named region 'conversion' with pre-specified column types[命名区域“转换”预先指定的列类型]
# Note: in the worksheet all data was entered as strings![注:在工作表中的所有数据输入字符串!]
# forceConversion = TRUE is used to force conversion from String[forceConversion = TRUE用于强制字符串转换]
# into the less generic data types Numeric, DateTime & Boolean[为不通用的数据类型,数字,日期和布尔]
df <- readNamedRegion(wb, name = "conversion", header = TRUE,
colTypes = c(XLC$DATA_TYPE.NUMERIC,
XLC$DATA_TYPE.DATETIME,
XLC$DATA_TYPE.BOOLEAN),
forceConversion = TRUE,
dateTimeFormat = "%Y-%m-%d %H:%M:%S")
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|