找回密码
 注册
查看: 1368|回复: 0

R语言 XLConnect包 readWorksheet-methods()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-10-1 23:26:48 | 显示全部楼层 |阅读模式
readWorksheet-methods(XLConnect)
readWorksheet-methods()所属R语言包:XLConnect

                                        Reading data from worksheets
                                         从工作表读取数据

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

Reads data from worksheets of a workbook.
从工作表的workbook中读取数据。


用法----------Usage----------


## S4 method for signature 'workbook,numeric'
readWorksheet(object,sheet,startRow,startCol,endRow,endCol,region,header,rownames,colTypes,forceConversion,dateTimeFormat,check.names)
## S4 method for signature 'workbook,character'
readWorksheet(object,sheet,startRow,startCol,endRow,endCol,region,header,rownames,colTypes,forceConversion,dateTimeFormat,check.names)



参数----------Arguments----------

参数:object
The workbook to use
workbook使用


参数:sheet
The name or index of the worksheet to read from
的工作表名称或索引读取


参数:startRow
The index of the first row to read from
要从中读取的第一行的索引


参数:startCol
The index of the first column to read from
第一列的索引来读取


参数:endRow
The index of the last row to read from
在最后一行的索引读取


参数:endCol
The index of the last column to read from
最后一列的索引读取


参数:region
A range specifier in the form 'A10:B18'. This provides an alternative way to specify startRow, startCol, endRow and endCol. Range specifications take precedence over index specifications.
一个范围中指定的形式为“A10:B18”。这提供了另一种方式来指定startRow,startCol,endRow和endCol。规格品种齐全的优先级高于指数规格。


参数:header
Interpret the first row of the specified area as column headers. The default is TRUE.
解释为列标题的指定区域中的第一行。默认的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----------

Reads data from the worksheet specified by sheet. Data is read starting at the top left corner specified by startRow and startCol down to the bottom right corner specified by endRow and endCol. If header = TRUE, the first row is interpreted as column names of the resulting data.frame.<br> If startRow <= 0 then the first available (logical) row is assumed. If startCol <= 0 then the column  of the first (logical) cell of the start row (startRow) is assumed. If endRow <= 0 then the last available  (logical) row is assumed. If endCol <= 0 then the maximum column between startRow and endRow is assumed.  In other words, if no boundaries are specified readWorksheet assumes  the "bounding box" of the data as the corresponding boundaries.<br><br>
读取指定的sheet从工作表中的数据。读取数据开始在左上角指定的startRow和startCol右下角指定的endRow和endCol。如果header = TRUE,第一行产生的data.frame。<BR>如果startRow <= 0然后假定第一个可用的(逻辑)行作为列名的解释。如果startCol <= 0然后列的第一个(逻辑)的单元的起始行(startRow)被假设。如果endRow <= 0然后最后一个可用的(逻辑)假设行。如果endCol <= 0然后startRow和endRow假定的最大列之间的。换句话说,如果没有指定边界readWorksheet假定“边界框”的数据作为相应的边界参考参考

If all four coordinate arguments are missing this behaves as above with startRow = 0, startCol = 0, endRow = 0 and endCol = 0. In this case  readWorksheet assumes the "bounding box" of the data as the corresponding boundaries.<br><br>
如果所有四个坐标参数丢失,这表现为上面的startRow = 0,startCol = 0,endRow = 0和endCol = 0。在这种情况下readWorksheet假定“边界框”的数据作为相应的边界参考参考

All arguments (except object) are vectorized. As such, multiple worksheets (and also multiple data regions from the same worksheet) can be read with one method call. If only one single data region is read, the return value  is a data.frame. If multiple data regions are specified, the return value is a list of data.frame's  returned in the order they have been specified. If worksheets have been specified by name, the list will be a named list named by the corresponding worksheets.
所有的参数(除了object)被量化的。因此,可以读取一个方法调用多个工作表(也有多个相同的工作表数据区域)。如果只有一个单一的数据区域被读取时,返回值是一个data.frame。如果指定了多个数据区域,返回值是一个listdata.frame返回他们已被指定的顺序。如果已指定名称的工作表,list将是一个名为list相应的工作表的名字命名的。


注意----------Note----------

If no specific column types (see argument colTypes) are specified, readWorksheet 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)被指定,readWorksheet试图读的单元类型的基础上确定最终的列类型。如果不同类型的单元中被发现特定列中,那些最一般的使用,并映射到相应的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>




参见----------See Also----------

workbook, writeWorksheet, readNamedRegion, writeNamedRegion,<br> readWorksheetFromFile, onErrorCell
workbook,writeWorksheet,readNamedRegion,writeNamedRegion,参考readWorksheetFromFile,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 worksheet 'mtcars' (providing no specific area bounds;[读表“mtcars”(没有提供特定区域边界;]
# with default header = TRUE)[默认的头= TRUE)]
data <- readWorksheet(wb, sheet = "mtcars")


## Example 2:[例2:]
# 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 worksheet 'mtcars' (providing area bounds; with default header = TRUE)[读取工作表“mtcars(提供区域界限,与默认的头= TRUE)]
data <- readWorksheet(wb, sheet = "mtcars", startRow = 1, startCol = 3,
                      endRow = 15, endCol = 8)


## Example 3:[例3:]
# 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 worksheet 'mtcars' (providing area bounds using the region argument;[读表“mtcars”(区域边界采用的是区域参数;]
# with default header = TRUE)[默认的头= TRUE)]
data <- readWorksheet(wb, sheet = "mtcars", region = "C1:H15")


## Example 4:[例4:]
# 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 worksheet '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 &amp; Boolean[为不通用的数据类型,数字,日期和布尔]
df <- readWorksheet(wb, sheet = "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:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2024-11-24 19:55 , Processed in 0.025546 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表