當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R語言 is.character()用法及代碼示例

is.character()R語言中的函數用於檢查對象是否為字符串/字符形式。如果對象的任何元素是字符數據類型,它將返回 true。

用法: is.character(Object)

參數:
Object:它可以是數組、列表、向量等。

範例1:


# R Program to illustrate 
# the use of is.character function
  
# Creating a vector of mixed datatype
x1 <- c("Hello", "Geeks", 100)
  
# Creating a vector of Numeric datatype
x2 <- c(10, 20, 30)
  
# Calling is.character() function
is.character(x1)
is.character(x2)

輸出:

[1] TRUE
[1] FALSE

範例2:


# R Program to illustrate 
# the use of is.character function
  
# Create the vectors with different length 
vector1 <- c(1, 2, 3) 
vector2 <- c("GFG", "Geeks", "Hello") 
    
# taking this vector as input 
result <- array(c(vector1, vector2), dim = c(3, 3, 2)) 
  
# Calling is.character() function
is.character(result)

輸出:

[1] TRUE

相關用法


注:本文由純淨天空篩選整理自nidhi_biet大神的英文原創作品 Check if Object is of the Character Data type in R Programming – is.character() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。