R语言 从数据框中提取向量

R语言 从数据框中提取向量

在这篇文章中,我们将看到如何在R编程语言中从DataFrame中提取向量。

方法很简单,通过使用 $操作符 ,我们可以将数据框架列转换为矢量。

语法

dataframe_name$columnname

下面是实现这一方法的各种例子

例1 :

# 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 data frame
data=data.frame(name,subjects,marks,height,weight)
  
# display dataframe
print(data)
  
# access vector from dataframe column name
a=(dataname)
print(a)
  
# access vector from dataframe column marks
b=(datamarks)
print(b)

输出

在R语言中从数据框中提取向量

例2 :

# 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 data frame
data=data.frame(height,weight)
  
# display dataframe
print(data)
  
# access vector from dataframe column
# weight
a=(dataweight)
print(a)
  
# access vector from dataframe column 
# height
b=(dataheight)
print(b)

输出

在R语言中从数据框中提取向量

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程