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


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

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

用法: is.integer(x)

參數:
x:檢查對象

範例1:


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

輸出:

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

範例2:


# R program to check if 
# object is an integer
  
# Creating a matrix
x1 <- matrix(c(1:9), 3, 3)
  
# Calling is.integer() function
is.integer(x1)

輸出:

[1] TRUE

相關用法


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