unname()R 語言中的函數用於從對象中刪除名稱或名稱。
用法: unname(x)
參數:
x:Object
範例1:
# R Program to remove names from an object
# Creating a matrix
A = matrix(c(1:9), 3, 3)
# Naming rows
rownames(A) = c("a", "b", "c")
# Naming columns
colnames(A) = c("c", "d", "e")
print(A)
# Removing names using unname() function
unname(A)輸出:
c d e
a 1 4 7
b 2 5 8
c 3 6 9
[, 1] [, 2] [, 3]
[1, ] 1 4 7
[2, ] 2 5 8
[3, ] 3 6 9
範例2:
# R Program to remove names from an object
# Calling pre-defined data set
BOD
# Removing names using unname() function
unname(BOD)輸出:
Time demand
1 1 8.3
2 2 10.3
3 3 19.0
4 4 16.0
5 5 15.6
6 7 19.8
1 1 8.3
2 2 10.3
3 3 19.0
4 4 16.0
5 5 15.6
6 7 19.8
相關用法
- R語言 names()用法及代碼示例
- R語言 unique()用法及代碼示例
- R語言 na.omit()用法及代碼示例
- R語言 sapply()用法及代碼示例
- R語言 identity()用法及代碼示例
- R語言 type.convert()用法及代碼示例
- R語言 which()用法及代碼示例
- R語言 call()用法及代碼示例
- R語言 cumprod()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi_biet大神的英文原創作品 Remove names or dimnames from an Object in R Programming – unname() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
