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


R語言 mode()用法及代碼示例


R語言中的mode()函數用於獲取或設置對象的類型或存儲方式。

用法:
mode(x)
mode(x) <- value
Here "value" is the desired mode or ‘storage mode’ (type) of the object

參數:
x:R對象

範例1:


# R program to illustrate
# mode function
  
# Initializing some values
x <- 3
y <- "a"
  
# Calling the mode() function 
mode(x)
mode(y)

輸出:

[1] "numeric"
[1] "character"

範例2:


# R program to illustrate
# mode function
  
# Initializing some values
x <- 3
y <- "a"
  
# Calling mode() function to
# set the storage mode of the object
mode(x) <- "character"
mode(y) <- "numeric"
  
# Getting the assigned storage mode
mode(x)
mode(y)

輸出:

[1] "character"
[1] "numeric"

相關用法


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