Get the Number of Levels of a Factor in R Programming - nlevels() Function Last Updated : 16 Jun, 2020 Comments Improve Suggest changes Like Article Like Report nlevels() function in R Language is used to get the number of levels of a factor. Syntax: nlevels(x) Parameters: x: Factor Object Example 1: Python3 1== # R program to get the number # of levels of a factor # Creating a factor x <- gl(3, 2) x # Calling nlevels() function # to get the number of levels nlevels(x) Output: [1] 1 1 2 2 3 3 Levels: 1 2 3 [1] 3 Example 2: Python3 1== # R program to get the number # of levels of a factor # Creating a factor gender <- factor(c("female", "male", "male", "female")); gender # Calling nlevels() function # to get the number of levels nlevels(gender) Output: [1] female male male female Levels: female male [1] 2 Comment More infoAdvertise with us Next Article Get the Number of Levels of a Factor in R Programming - nlevels() Function N nidhi_biet Follow Improve Article Tags : R Language R Factor-Function Similar Reads Get or Set Levels of a Factor in R Programming - levels() Function levels() function in R Language is used to get or set the levels of a factor. Syntax: levels(x) Parameters: x: Factor Object Example 1: Python3 1== # R program to get levels of a factor # Creating a factor gender <- factor(c("female", "male", "male", "female 1 min read Get the number of columns of an Object in R Programming - ncol() Function ncol() function in R Language is used to return the number of columns of the specified matrix. Syntax: ncol(x)Parameters: x: matrix, vector, array or data frame  Example 1:  Python3 # R program to illustrate # ncol function # Getting R Biochemical Oxygen Demand Dataset BOD # Calling ncol() functi 1 min read Get the number of rows of an Object in R Programming - nrow() Function nrow() function in R Language is used to return the number of rows of the specified matrix. Syntax: nrow(x)Parameters: x: matrix, vector, array or data frame  Example 1:  Python3 # R program to illustrate # nrow function # Getting R Biochemical Oxygen Demand Dataset BOD # Calling nrow() function 1 min read Getting a Matrix of number of columns in R Programming - col() Function col() function in R Language is used to get a matrix which contains the number of columns of the matrix passed to it as argument. Syntax: col(x, as.factor=FALSE) Parameters: x: matrix as.factor: a logical value indicating whether the value should be returned as a factor of column labels (created if 2 min read Generate Factors with specified Levels in R Programming - gl() Function gl() function in R Language is used to generate factors by specifying the pattern of their levels. Syntax: gl(x, k, length, labels, ordered) Parameters: x: Number of levels k: Number of replications length: Length of result labels: Labels for the vector(optional) ordered: Boolean value to order the 2 min read Like