read.xlsx(xlsx)
read.xlsx()所属R语言包:xlsx
Read the contents of a worksheet into an R data.frame
阅读一个工作表的内容到一个R数据框
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Read the contents of a worksheet into an R data.frame.
阅读内容的工作表Rdata.frame。
用法----------Usage----------
read.xlsx(file, sheetIndex, sheetName=NULL, rowIndex=NULL,
colIndex=NULL, as.data.frame=TRUE, header=TRUE, colClasses=NA,
keepFormulas=FALSE, encoding="unknown", ...)
read.xlsx2(file, sheetIndex, sheetName=NULL, startRow=1,
colIndex=NULL, endRow=NULL, as.data.frame=TRUE, header=TRUE,
colClasses="character", ...)
参数----------Arguments----------
参数:file
the absolute path to the file which the data are to be read from.
该数据要被读取的文件的绝对路径。
参数:sheetIndex
a number representing the sheet index in the workbook.
一个数字,表示在工作簿中的表的索引。
参数:sheetName
a character string with the sheet name.
工作表名称的字符串。
参数:rowIndex
a numeric vector indicating the rows you want to extract. If NULL, all rows found will be extracted.
一个数值向量,表示你要提取的行。如果NULL,将提取的所有行。
参数:colIndex
a numeric vector indicating the cols you want to extract. If NULL, all columns found will be extracted.
一个数值向量,表示要提取的列。如果NULL,将提取的所有列。
参数:as.data.frame
a logical value indicating if the result should be coerced into a data.frame. If FALSE, the result is a list with one element for each column.
逻辑值,如果结果被裹挟到一个data.frame。如果FALSE,其结果是为每列包含一个元素的列表。
参数:header
a logical value indicating whether the first row corresponding to the first element of the rowIndex vector contains the names of the variables.
一个逻辑值,该值指示rowIndex矢量相对应的第一行的第一个元素是否包含的变量名称。
参数:colClasses
For read.xlsx a character vector that represent the class of each column. Recycled as necessary, or if the character vector is named, unspecified values are taken to be NA. For read.xlsx2 A character vector, recycled if necessary. Only numeric and character values are allowed.
对于read.xlsx字符向量,每一列代表的类。回收是必要的,或者未指定值特征向量的命名,采取的是NA。对于read.xlsx2字符向量,回收如果必要的话。只有numeric和character值是不允许的。
参数:keepFormulas
a logical value indicating if Excel formulas should be shown as text in R and not evaluated before bringing them in.
一逻辑值,表示如果Excel公式应在R作为文本显示,而不是前评估他们。
参数:encoding
encoding to be assumed for input strings. See read.table.
输入字符串编码来承担。见read.table。
参数:startRow
an numeric specifying the index of starting row.
数字指定索引的起始行。
参数:endRow
an numeric specifying the index of the last row to pull. If NULL, read all the rows in the sheet.
数字指定索引的最后一排,拉。如果NULL,读取工作表中的所有行。
参数:...
other arguments to data.frame, for example stringsAsFactors
其他参数data.frame,例如stringsAsFactors
Details
详细信息----------Details----------
The read.xlsx function provides a high level API for reading data from an Excel worksheet. It calls several low level functions in the process. Its goal is to provide the conveniency of read.table by borrowing from its signature.
read.xlsx的函数提供了一个高层次的API来读取数据从Excel工作表。它调用几个低级别的功能,在这个过程中。它的目标是通过其签名的借款提供的方便性read.table。
The function pulls the value of each non empty cell in the worksheet into a vector of type list by preserving the data type. If as.data.frame=TRUE, this vector of lists is then formatted into a rectangular shape. Special care is needed for worksheets with ragged data.
的功能拉成一个向量类型的值的每一个非空单元格在工作表中list通过保存的数据类型。如果as.data.frame=TRUE,此向量的列表,然后格式化成一个矩形的形状。特别是需要与衣衫褴褛的数据的工作表。
The class type of the variable corresponding to one column in the worksheet is taken from the class of the first non empty cell in that column. If you need to impose a specific class type on a variable, use the colClasses argument.
从该列的第一个非空单元格中的类的类类型的变量相应的工作表中的一列。如果你需要施加一个特定的类类型变量,使用colClasses参数。
Excel internally stores dates and datetimes as numeric values, and does not keep track of time zones and DST. When a datetime column is brought into R, it is converted to POSIXct class with a GMT timezone. Occasional rounding errors may appear and the R and Excel string representation my differ by one second. For read.xlsx2 bring in a datetime column as a numeric one and then convert to class POSIXct or Date.
Excel在内部存储的数值,日期和日期时间和时区和DST不跟踪。当datetime列的赞助商为R,它被转换为POSIXct类与GMT时区。偶尔舍入误差可能会出现一秒钟的R和Excel的字符串表示我的不同。对于read.xlsx2带来的datetime列的数字,然后转换类POSIXct或Date。
The read.xlsx2 function does more work in Java so it achieves better performance (an order of magnitude faster on sheets with 100,000 cells or more). The result of read.xlsx2 will in general be different from read.xlsx, because internally read.xlsx2 uses readColumns which is tailored for tabular data.
read.xlsx2功能在Java中做更多的工作,以便获得更好的性能(速度之快超过10万个单元或上表)。的结果read.xlsx2一般会从read.xlsx是不同的,因为内部read.xlsx2使用readColumns是专为表格数据。
值----------Value----------
A data.frame or a list, depending on the as.data.frame argument.
数据框或列表,根据as.data.frame参数。
(作者)----------Author(s)----------
Adrian Dragulescu
参见----------See Also----------
write.xlsx for writing xlsx documents. See also readColumns for reading only a set of columns
write.xlsx写xlsx文件。 readColumns只读取一组列
实例----------Examples----------
## Not run: [#不运行:]
file <- system.file("tests", "test_import.xlsx", package = "xlsx")
res <- read.xlsx(file, 1) # read first sheet[先读表]
head(res)
# NA. Population Income Illiteracy Life.Exp Murder HS.Grad Frost Area[NA。谋杀HS.Grad冻土区域的居民收入文盲Life.Exp]
# 1 Alabama 3615 3624 2.1 69.05 15.1 41.3 20 50708[阿拉巴马州3615 3624 2.1 69.05 15.1 41.3 20 50708]
# 2 Alaska 365 6315 1.5 69.31 11.3 66.7 152 566432[阿拉斯加365 6315 1.5 69.31 11.3 66.7 152 566432]
# 3 Arizona 2212 4530 1.8 70.55 7.8 58.1 15 113417[美国亚利桑那州2212 4530 1.8 70.55 7.8 58.1 15 113417]
# 4 Arkansas 2110 3378 1.9 70.66 10.1 39.9 65 51945[4阿肯色州2110 3378 1.9 70.66 10.1 39.9 65 51945]
# 5 California 21198 5114 1.1 71.71 10.3 62.6 20 156361[5加州21198 5114 1.1 71.71 10.3 62.6 20 156361]
# 6 Colorado 2541 4884 0.7 72.06 6.8 63.9 166 103766[6科罗拉多2541 4884 0.7 72.06 6.8 63.9 166 103766]
# >[>]
# To convert an Excel datetime colum to POSIXct, do something like:[要转换为Excel日期时间柱POSIXct,做这样的事情:]
# as.POSIXct((x-25569)*86400, tz="GMT", origin="1970-01-01")[as.POSIXct((X-25569)* 86400,TZ =“GMT”,起源=“1970-01-01”)]
# For Dates, use a conversion like:[对于日期,使用一个转换,如:]
# as.Date(x-25569, origin="1970-01-01") [as.Date(X-25569,产地=“1970-01-01”)]
res2 <- read.xlsx2(file, 1)
## End(Not run)[#(不执行)]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|