View source: R/category_vector.R
| category_vector | R Documentation |
Convert an object containing binary (integer) columns into a
integer vector indicating the column index where each row is
1.
category_vector(x)
## S3 method for class 'data.frame'
category_vector(x)
## S3 method for class 'sf'
category_vector(x)
## S3 method for class 'Spatial'
category_vector(x)
## S3 method for class 'matrix'
category_vector(x)
x |
|
This function is conceptually similar to base::max.col()
except that rows with no values equal to 1 values are assigned a
value of zero. Also, note that in the argument to x, each row must
contain only a single value equal to 1.
An integer vector.
base::max.col().
# create matrix with logical columns
x <- matrix(c(1, 0, 0, NA, 0, 1, 0, NA, 0, 0, 0, NA), ncol = 3)
# print matrix
print(x)
# convert to category vector
y <- category_vector(x)
# print category vector
print(y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.