R语言 如何颠倒给定向量的顺序
在这篇文章中,我们将讨论如何使用R编程语言中的 rev() 函数来逆转向量中的元素顺序。
语法:
rev(vector_name)
处理方法
- 创建一个向量
- 反转元素
创建一个向量的语法 。
C(value1,value2,...,valuen)
例子: 创建向量
# create vector with names
name=c("sravan","mohan","sudheer","radha","vani","mohan")
# create vector with subjects
subjects=c(".net","Python","java","dbms","os","dbms")
# create a vector with marks
marks=c(98,97,89,90,87,90)
# create vector with height
height=c(5.97,6.11,5.89,5.45,5.78,6.0)
# create vector with weight
weight=c(67,65,78,65,81,76)
# pass these vectors to the vector
data=c(name,subjects,marks,height,weight)
# display
print(data)
输出
例子: 倒转元素的顺序
print("reverse")
print(rev(name))
print(rev(subjects))
print(rev(marks))
print(rev(height))
print(rev(weight))
输出。