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

R语言 IRanges包 DataFrame-class()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-25 22:26:17 | 显示全部楼层 |阅读模式
DataFrame-class(IRanges)
DataFrame-class()所属R语言包:IRanges

                                        External Data Frame
                                         外部数据框

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

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

The DataFrame extends the DataTable virtual class and supports the storage of any type of object (with length and [ methods) as columns.
DataFrame延伸DataTable虚类,并支持存储任何类型的对象(length和[方法)作为列。


Details

详情----------Details----------

On the whole, the DataFrame behaves very similarly to data.frame, in terms of construction, subsetting, splitting, combining, etc. The most notable exception is that the row names are optional. This means calling rownames(x) will return NULL if there are no row names. Of course, it could return seq_len(nrow(x)), but returning NULL informs, for example, combination functions that no row names are desired (they are often a luxury when dealing with large data).
就整体而言,DataFrame的行为非常类似data.frame,在建设方面,子集,分割,合并等最显着的例外是该行的名称是可选的。这意味着调用rownames(x)将返回NULL如果没有行名称。当然,它可以返回seq_len(nrow(x)),但回NULL通知,例如,没有行名称所需的(他们往往是奢侈品处理大量数据时)的组合功能。

As DataFrame derives from Vector, it is possible to set an annotation string. Also, another DataFrame can hold metadata on the columns.
DataFrame来自Vector,它可以设置一个annotation字符串。此外,另一个DataFrame可容纳列的元数据。

For a class to be supported as a column, it must have length and [ methods, where [ supports subsetting only by i and respects drop=FALSE. Optionally, a method may be defined for the showAsCell generic, which should return a vector of the same length as the subset of the column passed to it. This vector is then placed into a data.frame and converted to text with format. Thus, each element of the vector should be some simple, usually character, representation of the corresponding element in the column.
对于被视为一列支持的类,它必须有length和[方法,[支持只能由i尊重drop=FALSE子集。可选的方法可为showAsCell通用的,它应该返回一个相同长度的向量作为列的子集传递给它的定义。这个向量,然后放入一个data.frame和format转换为文本。因此,向量的每个元素应该是一些简单的,通常的性格,列中的相应元素的代表性。


存取----------Accessors----------

In the following code snippets, x is a DataFrame.
在下面的代码片段,x是DataFrame。




dim(x): Get the length two integer vector indicating in the first and second element the number of rows and columns, respectively.
dim(x):获取长度为两个整数向量表示的行和列,分别在第一和第二个元素。




dimnames(x), dimnames(x) <- value: Get and set the two element list containing the row names (character vector of length nrow(x) or NULL) and the column names (character vector of length ncol(x)).
dimnames(x),dimnames(x) <- value:获取和设置两个元素的列表包含行名称(字符向量的长度nrow(x)或NULL)和列名(字符长度矢量 ncol(x))。


子集----------Subsetting----------

In the following code snippets, x is a DataFrame.
在下面的代码片段,x是DataFrame。




x[i,j,drop]: Behaves very similarly to the [.data.frame method, except i can be a logical Rle object and subsetting by matrix indices is not supported. Indices containing NA's are also not supported.
x[i,j,drop]:行为非常类似[.data.frame方法,除了,i可以是一个逻辑Rlematrix指数不支持的对象和子集。指数包含NA的也没有支持。




x[i,j] <- value: Behaves very similarly to the [<-.data.frame method.
x[i,j] <- value:[<-.data.frame方法的表现非常相似。




x[[i]]: Behaves very similarly to the [[.data.frame method, except arguments j and exact are not supported. Column name matching is always exact. Subsetting by matrices is not supported.
x[[i]]:行为非常类似[[.data.frame方法,参数除外j和exact不支持。列名匹配始终是准确的。不支持矩阵子集。




x[[i]] <- value: Behaves very similarly to the [[<-.data.frame method, except argument j is not supported.
x[[i]] <- value:[[<-.data.frame方法的表现非常相似,除了参数j不支持。


构造----------Constructor----------

DataFrame(..., row.names = NULL): Constructs a DataFrame in similar fashion to data.frame. Each argument in ... is coerced to a DataFrame and combined column-wise. No special effort is expended to automatically determine the row names from the arguments. The row names should be given in row.names; otherwise, there are no row names. This is by design, as row names are normally undesirable when data is large.
DataFrame(..., row.names = NULL):构造一个类似的方式DataFramedata.frame。每个...的论点被裹挟至1 DataFrame并结合列明智的。没有什么特别的努力,花费从参数自动确定的行名。行的名称应当给予row.names,否则,有没有行的名称。这是由设计,为行名通常是不可取的,当数据大。

To store an object of a class that does not support coercion to DataFrame, wrap it in I(). The class must still have methods for length and [.
要存储一个类的对象,不支持强制DataFrame,包装在I()。类的,还必须有方法length和[。


分裂和结合----------Splitting and Combining----------

In the following code snippets, x is a DataFrame.
在下面的代码片段,x是DataFrame。




split(x, f, drop = FALSE): Splits x into a CompressedSplitDataFrameList, according to f, dropping elements corresponding to unrepresented levels if drop is TRUE.
split(x, f, drop = FALSE):拆分:x到CompressedSplitDataFrameList,根据f,删除对应的元素,没有律师代表的水平,如果drop是TRUE。

rbind(...): Creates a new DataFrame by combining the rows of the DataFrame objects in .... Very similar to rbind.data.frame, except in the handling of row names. If all elements have row names, they are concatenated and made unique. Otherwise, the result does not have row names. Currently, factors are not handled well (their levels are dropped). This is not a high priority until there is an XFactor class.
rbind(...):创建一个新的DataFrameDataFrame行...对象相结合。 rbind.data.frame,除在处理行名称非常相似。如果所有的元素都行名,他们是连接在一起,并作出独特的。否则,其结果不具有行名称。目前,因素没有处理好(被丢弃的水平)。这不是一个高度优先事项,直到有一个XFactor类。

cbind(...): Creates a new DataFrame by combining the columns of the DataFrame objects in .... Very similar to cbind.data.frame, except row names, if any, are dropped. Consider the DataFrame as an alternative that allows one to specify row names.
cbind(...):创建一个新的DataFrameDataFrame的...对象的列相结合。 cbind.data.frame非常相似,除行名,如果有的话,被丢弃。考虑作为替代方案,允许指定行名称DataFrame。


聚合----------Aggregation----------

In the following code snippets, data is a DataFrame.
在下面的代码片段,data是DataFrame。




aggregate(x, data, FUN, ..., subset, na.action = na.omit): Aggregates the DataFrame data according to the formula x and the aggregating function FUN. See aggregate and its method for formula.
aggregate(x, data, FUN, ..., subset, na.action = na.omit):聚合DataFramedata根据公式x和聚合函数FUN。看到aggregate和formula方法。


强迫----------Coercion----------




as(from, "DataFrame"): By default, constructs a new DataFrame with from as its only column. If from is a matrix or data.frame, all of its columns become columns in the new DataFrame. If from is a list, each element becomes a column, recycling as necessary. Note that for the DataFrame to behave correctly, each column object must support element-wise subsetting via the [ method and return the number of elements with length. It is recommended to use the DataFrame  constructor, rather than this interface.
as(from, "DataFrame"):默认情况下,构建一个新的DataFrame与from作为其唯一的列。如果from是matrix或data.frame,其所有的列,成为在新的DataFrame列。如果from是一个列表,每个元素成为一列,必要时回收。注意DataFrame正确的行为,每列的对象必须支持通过[方法明智的元素,子集,并返回元素length的数量。建议使用DataFrame构造函数,而不是接口。




as.list(x): Coerces x, a DataFrame, to a list.
as.list(x):胁迫x,DataFrame,list。




as.data.frame(x, row.names=NULL, optional=FALSE): Coerces x, a DataFrame, to a data.frame. Each column is coerced to a data.frame and then column bound together. If row.names is NULL, they are retrieved from x, if it has any. Otherwise, they are inferred by the data.frame constructor.
as.data.frame(x, row.names=NULL, optional=FALSE):胁迫x,DataFrame,data.frame。每一列都被裹挟到data.frame然后列捆绑在一起。 row.names如果是NULL,他们从x检索,如果有任何。否则,他们推断data.frame构造。

NOTE: conversion of x to a data.frame is not supported if x contains any list, SimpleList, or CompressedList columns.
注:转换的xdata.frame的如果x包含任何list,SimpleList或CompressedList列,不支持。




as(from, "data.frame"): Coerces a DataFrame to a data.frame by calling as.data.frame(from).
as(from, "data.frame"):DataFrame胁迫一调用data.frameas.data.frame(from)。


作者(S)----------Author(s)----------


Michael Lawrence



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

DataTable, Vector, and RangedData, which makes heavy use of this class.
DataTable,Vector,RangedData,这使得大量使用这个类。


举例----------Examples----------


  score <- c(1L, 3L, NA)
  counts <- c(10L, 2L, NA)
  row.names <- c("one", "two", "three")
  
  df &lt;- DataFrame(score) # single column[单柱]
  df[["score"]]
  df &lt;- DataFrame(score, row.names = row.names) #with row names[行名]
  rownames(df)
  
  df &lt;- DataFrame(vals = score) # explicit naming[明确命名]
  df[["vals"]]
  
  # a data.frame[数据框]
  sw <- DataFrame(swiss)
  as.data.frame(sw) # swiss, without row names[瑞士,无行名]
  # now with row names[现在行名称]
  sw <- DataFrame(swiss, row.names = rownames(swiss))
  as.data.frame(sw) # swiss[瑞士的]

  # subsetting[子集]
   
  sw[] # identity subset[身份的子集]
  sw[,] # same[同]

  sw[NULL] # no columns[没有列]
  sw[,NULL] # no columns[没有列]
  sw[NULL,] # no rows[任何行]

  ## select columns[#选择列]
  sw[1:3]
  sw[,1:3] # same as above[与上述相同]
  sw[,"Fertility"]
  sw[,c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE)]

  ## select rows and columns[#选择行和列]
  sw[4:5, 1:3]
  
  sw[1] # one-column DataFrame[一列DataFrame的]
  ## the same[#]
  sw[, 1, drop = FALSE]
  sw[, 1] # a (unnamed) vector[(无名)向量]
  sw[[1]] # the same[同一]
  sw[["Fertility"]]

  sw[["Fert"]] # should return 'NULL'[应该返回“NULL”]
  
  sw[1,] # a one-row DataFrame[一个行DataFrame,]
  sw[1,, drop=TRUE] # a list[列表]

  ## duplicate row, unique row names are created[#重复的行,创建独特的行名]
  sw[c(1, 1:2),]

  ## indexing by row names  [#行名称索引]
  sw["Courtelary",]
  subsw <- sw[1:5,1:4]
  subsw["C",] # partially matches[部分匹配]

  ## row and column names[#行和列名]
  cn <- paste("X", seq_len(ncol(swiss)), sep = ".")
  colnames(sw) <- cn
  colnames(sw)
  rn <- seq(nrow(sw))
  rownames(sw) <- rn
  rownames(sw)

  ## column replacement[#列更换]

  df[["counts"]] <- counts
  df[["counts"]]
  df[[3]] <- score
  df[["X"]]
  df[[3]] &lt;- NULL # deletion[删除]

  ## split[#分裂]

  sw <- DataFrame(swiss)
  swsplit <- split(sw, sw[["Education"]])
  
  ## rbind[#rbind]

  do.call(rbind, as.list(swsplit))

  ## cbind[#cbind]

  cbind(DataFrame(score), DataFrame(counts))

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-2-5 13:51 , Processed in 0.025528 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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