This is a short question, but how do I look up the dimensions of a factor variable in R? I tried:

dim(X)
nrow(X)
ncol(X)

but all return NULL

有帮助吗?

解决方案

If we have an atomic variable (which a factor is), it will have a length value

X <- factor(letters)

length(X)

## [1] 26

It will also have levels

levels(x)

When X is a factor, it is the following classes

is(X)
[1] "factor"   "integer"  "oldClass" "numeric"  "vector"  

其他提示

Also the str() function is helpful when one has a dataframe and needs to get an idea of many different levels at once.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top