当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R语言 is.ordered()用法及代码示例


is.ordered()R语言中的函数用于检查传递的因子是否为有序因子。

用法: is.ordered(factor)

参数:
factor:检查因子

范例1:


# Creating a vector 
x<-c("female", "male", "male", "female") 
  
# Converting vector into factor
gender <- factor(x)
  
# Using is.ordered() Function
# to check if a factor is ordered
is.ordered(gender)

输出:

[1] FALSE

范例2:


# creating vector size 
size = c("small", "large", "large", "small",  
         "medium", "large", "medium", "medium")   
sizes <- ordered(c("small", "large", "large", 
                   "small", "medium")) 
    
# ordering the levels 
sizes <- ordered(sizes, levels = c("small", "medium", "large"))     
  
# Checking if the factor is ordered
# using is.ordered() function
is.ordered(sizes)

输出:

[1] TRUE

相关用法


注:本文由纯净天空筛选整理自nidhi_biet大神的英文原创作品 Check if a Factor is an Ordered Factor in R Programming – is.ordered() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。