要编写一个 R 程序来创建向量并计算其长度和维度,我们使用内置函数 dim() 和 length()。
它们的语法是:
dim(x)
length(x)
在这个 R 程序中,我们直接将值赋给内置函数,在此之前我们显示向量值。然后,我们考虑变量 A,其中分配了向量值。调用函数 dim() 用于查找维度,调用 length() 用于查找向量的长度。最后,打印结果。
步骤 1: 将向量值赋给变量 A
步骤 2: 显示实际的向量值
步骤 3: 调用函数 dim(),例如 dim(A)
步骤 4: 打印函数的结果
步骤 5: 调用函数 length(),例如 length(A)
步骤 6: 打印函数的结果
A = c(1,3,5,7,9,6)
print("Original vectors is:")
print(A)
print("Dimension of the vector is:")
print(dim(A))
print("length of the vector is:")
print(length(A))
[1] "Original vectors is:" [1] 1 3 5 7 9 6 [1] "Dimension of the vector is:" NULL [1] "length of the vector is:" [1] 6