R語言 c()函數 官方 說明文檔

需要注意的是,cbind() 和rbind() 是考慮dim 特性的連接函數,而函數c() 則不考慮這些數值對象的dim 和dimnames 屬性。這一點在有些時候非常有用。將一個數組強制轉換成簡單向量的標準方法是用函數as.vector()。

vec <- as.vector(X)
一個相似效果的辦法是採用單參數的c()函數,就像下面:
vec <- c(X)
這兩種方法有少許不同,到底採用那種方式關鍵是看對結果向量的格式要求(建議使用前者)。

c(base)
c()所屬R語言包:base
Combine Values into a Vector or List
結合成一個向量或列表值
譯者:生物統計家園網 機器人LoveR
描述----------Description----------
This is a generic function which combines its arguments.
這是一個通用的功能,結合其參數。
The default method combines its arguments to form a vector. All arguments are coerced to a common type which is the type of the returned value, and all attributes except names are removed.
默認的方法,結合它的參數,以形成一個向量。所有的參數被強制到一個共同的類型是返回值的類型,除名稱外,所有屬性將被刪除。
用法----------Usage----------
c(…, recursive=FALSE)
參數----------Arguments----------
參數:…
objects to be concatenated.
要連接的對象。
參數:recursive
logical. If recursive = TRUE, the function recursively descends through lists (and pairlists) combining all their elements into a vector.
邏輯。如果recursive = TRUE,函數的遞歸下降通過結合成一個向量元素(和pairlists)的名單。
Details
詳情----------Details----------
The output type is determined from the highest type of the components in the hierarchy NULL < raw < logical < integer < real < complex < character < list < expression. Pairlists are treated as lists, but non-vector components (such names and calls) are treated as one-element lists which cannot be unlisted even if recursive = TRUE.
輸出類型決定從最高的組件層次結構中的NULL類型<原料<邏輯<整數<真正複雜的<字符<列表<表達。的pairlists名單,但被視爲非向量組件(如姓名,電話)作爲一個元素列表,而不能是未上市,甚至如果recursive = TRUE治療。
c is sometimes used for its side effect of removing attributes except names, for example to turn an array into a vector. as.vector is a more intuitive way to do this, but also drops names. Note too that methods other than the default are not required to do this (and they will almost certainly preserve a class attribute).
c有時其副作用,除了名稱刪除屬性,例如變成一個向量數組。 as.vector是一個更直觀的方式做到這一點,但也下降名稱。太注意默認以外的方法,並不需要做到這一點(和他們幾乎肯定會維持一個類的屬性)。
This is a primitive function.
這是一種原始的功能。
值----------Value----------
NULL or an expression or a vector of an appropriate mode. (With no arguments the value is NULL.)
NULL或適當的方式表達或向量。 (不帶參數的值是NULL。)
S4方法----------S4 methods----------
This function is S4 generic, but with argument list (x, …, recursive = FALSE).
此功能是S4通用的,但參數列表(x, …, recursive = FALSE)。
參考文獻----------References----------
The New S Language. Wadsworth & Brooks/Cole.
參見----------See Also----------
unlist and as.vector to produce attribute-free vectors.
unlist和as.vector屬性的向量。
舉例----------Examples----------
c(1,7:9)
c(1:5, 10.5, “next”)

uses with a single argument to drop attributes[#使用一個參數,刪除屬性]

x <- 1:4
names(x) <- letters[1:4]
x
c(x) # has names[有名字]
as.vector(x) # no names[沒有名字]
dim(x) <- c(2,2)
x
c(x)
as.vector(x)

append to a list:[#附加到一個列表:]

ll <- list(A = 1, c=“C”)

do not use[#使用]

c(ll, d = 1:3) # which is == c(ll, as.list(c(d=1:3))[這是== C(LL,as.list(C(D = 1:3))]

but rather[#而是]

c(ll, d = list(1:3))# c() combining two lists[C()相結合的兩個列表]
c(list(A=c(B=1)), recursive=TRUE)
c(options(), recursive=TRUE)
c(list(A=c(B=1,C=2), B=c(E=7)), recursive=TRUE)
轉載請註明:出自 生物統計家園網(http://www.biostatistic.net)。

http://www.biostatistic.net/thread-2396-1-1.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章