Description Usage Arguments Details Value Note Author(s) See Also Examples
Split data column-wise on data.frame
,
matrix
and array
or element-wise on a
list
.
1 |
X |
A |
INDEX |
A factor of |
FUN |
A function to be applied to individual subset
of data (each factor level). If not provided
( |
... |
Additional arguments to |
Function splits a data.frame
, matrix
and
array
column-wise according to INDEX
and
list
is sliced according to INDEX
. Output
is returned as a list of the same length as the number of
levels in INDEX
.
A list of the same length as there are factor levels in
INDEX
.
Simplification sensu tapply
is not yet
implemented.
Roman Lustrik roman.lustrik@gmail.com
tapply
, by
,
aggregate
, apply
,
split
1 2 3 4 5 6 7 8 9 10 11 12 | my.list <- list(a = runif(5), b = runif(5), c = runif(5), d = runif(5), e = runif(10),
f = runif(10), g = runif(10), h = runif(10), i = runif(10), j = runif(10))
my.df <- as.data.frame(my.list)
my.matrix <- as.matrix(my.df)
ind <- factor(c(1,1,1,1, 2,3, 4,4,4,4))
ind2 <- factor(c(1,1,1,1, 2,3, 4,4,4,4), levels = 1:5)
# applies mean to each, you must use \code{colMeans} as \code{mean} is deprecated for \code{data.frame}s
splitc(X = my.df, INDEX = ind, FUN = colMeans)
splitc(X = my.matrix, INDEX = ind2) # level 5 empty because not populated
splitc(X = my.list, INDEX = ind, FUN = sum) # applied to elements INDEX-wise
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.