R语言 如何按名称选择DataFrame的多个列

R语言 如何按名称选择DataFrame的多个列

在这篇文章中,我们将讨论如何在R编程语言中按名称从DataFrame中选择多列。为了获得多列,我们将使用列表数据结构。通过使用一个列表,我们可以传递用逗号分隔的数据框架列。然后,我们可以通过使用list()函数获得列表。

语法:

list(dataframe_namecolumn1,dataframe_namecolumn2,. ,dataframe_name$column n)

例子1 :

# create a vector with student id
vector1=c(7058,7059,7075,7076)
  
# create a vector with student name
vector2=c("Sravan kumar","Jyothika",
          "Deepika","Kyathi")
  
# create a vector with student address
vector3=c("ponnur","tenali","repalle",
          "ponnur")
  
# pass these vectors to the dataframe
dataframe1=data.frame(id=vector1,names=vector2,
                      address=vector3)
  
print(dataframe1)
  
# select multiple columns from the
# dataframe1 using list datastructure
a=list(dataframe1id,dataframe1names,dataframe1$address)
  
print(a)

输出

如何在R语言中按名称选择DataFrame的多个列?

例2 :

# create a vector with student id
vector1=c(7058,7059,7075,7076)
  
# create a vector with student name
vector2=c("Sravan kumar","Jyothika",
          "Deepika","Kyathi")
  
# create a vector with student address
vector3=c("ponnur","tenali","repalle","ponnur")
  
# pass these vectors to the dataframe
dataframe1=data.frame(id=vector1,names=vector2,
                      address=vector3)
  
print(dataframe1)
  
# select multiple columns from the
# dataframe1 using list datastructure
a=list(dataframe1id,dataframe1names)
  
print(a)

输出

如何在R语言中按名称选择DataFrame的多个列?

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程