从 R 编程中的对象中删除名称或暗名称 - unname()函数
R 语言中的unname()
函数用于从对象中删除名称或暗名。
Syntax: unname(x)
Parameters:
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