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


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


is.character()R語言中的函數用於檢查作為參數傳遞給它的對象是否為字符類型。

用法: is.character(x)

參數:
x:檢查對象

範例1:


# R program to check if 
# object is a character
  
# Creating a vector
x1 <- 4
x2 <- c("a", "b", "c", "d")
x3 <- c(1, 2, "a", 3, "b")
  
# Calling is.character() function
is.character(x1)
is.character(x2)
is.character(x3)

輸出:

[1] FALSE
[1] TRUE
[1] TRUE

範例2:


# R program to check if 
# object is a character
  
# Creating a matrix
x1 <- matrix(letters[1:9], 3, 3)
  
# Calling is.character() function
is.character(x1)

輸出:

[1] TRUE

相關用法


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