pickcol | R Documentation |
This function will return colnames
or column values (if
value = TRUE
) for "indicator-like" matrices or data frames.
pickcol(data, ind = 1L, value = FALSE, default = NA)
data |
a data frame or matrix |
ind |
if |
value |
logical; if |
default |
for |
If value
is FALSE
(default), the column names of data
for which each row of data
contained ind
.
If value
is TRUE
, the column values of data
which are
not values of ind
.
set.seed(1)
ss <- sample(10)
dd <- as.matrix(ftable(1:10, ss))
all(pickcol(dd) == ss)
rn <- rnorm(10)
dd[dd == 1] <- rn
all(pickcol(dd, value = TRUE, ind = 0) == rowSums(dd))
dd <- data.frame(
x = c(1, 0, 0, NA),
y = c(0, 0, 1, NA),
z = c(0, 1, 0, NA),
a = c('one', '', '', NA),
b = c('', '', 'three', NA),
c = c('', 'two', '', NA)
)
pickcol(dd[1:2])
pickcol(dd[1:2], 0)
pickcol(dd[1:3] + 1, ind = 2)
pickcol(dd[4:6], value = TRUE, ind = '')
pickcol(dd, value = TRUE, ind = c('', 0:1))
dd[dd == ''] <- NA
pickcol(dd[4:6], value = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.