Extract.factor {base}R Documentation

Extract or Replace Parts of a Factor


Extract or replace subsets of factors.


## S3 method for class 'factor':
x[..., drop = FALSE]
## S3 method for class 'factor':
## S3 method for class 'factor':
x[...] <- value


x a factor
..., i a specification of indices – see Extract.
drop logical. If true, unused levels are dropped.
value character: a set of levels. Factor values are coerced to character.


When unused levels are dropped the ordering of the remaining levels is preserved.

If value is not in levels(x), a missing value is assigned with a warning.

Any contrasts assigned to the factor are preserved unless drop=TRUE.


A factor with the same set of levels as x unless drop=TRUE. (Prior to R 2.4.0, [[ returned the integer code.)

See Also

factor, Extract.


## following example(factor)
(ff <- factor(substring("statistics", 1:10, 1:10), levels=letters))
ff[, drop=TRUE]
factor(letters[7:10])[2:3, drop = TRUE]

[Package base version 2.5.0 Index]