在 R 编程中检查对象是否为表 - is.table()函数
R 语言中的is.table()
函数用于检查对象是否为表。
Syntax: is.table(x)
Parameters:
x: Object to be checked
示例 1:
# R Program to check
# if an object is a table
# Creating a vector
vec = c(2, 4, 3, 1, 2, 3, 2, 1, 4, 2)
# calling is.table() Function
is.table(vec)
# Converting to table
x <- as.table(vec)
x
# Calling is.table() again
is.table(x)
输出:
[1] FALSE
A B C D E F G H I J
2 4 3 1 2 3 2 1 4 2
[1] TRUE
示例 2:
# R Program to convert
# an object to a table
# Creating a matrix
mat = matrix(c(1:9), 3, 3)
# Calling is.table() function
is.table(mat)
# Converting to table
x <- as.table(mat)
x
# Calling is.table() function again
is.table(x)
输出:
[1] FALSE
A B C
A 1 4 7
B 2 5 8
C 3 6 9
[1] TRUE