Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用列表内容设置数据集的列名_R_List_Dataframe_Names_Col - Fatal编程技术网

R 使用列表内容设置数据集的列名

R 使用列表内容设置数据集的列名,r,list,dataframe,names,col,R,List,Dataframe,Names,Col,我读了一个包含数据的表和一个包含相应列名的列表。现在我想用Headrs的内容设置TestTR的列名: TestTR: V1 V2 V3 2 20 200 1 10 100 3 30 300 Headrs: Name1 Name2 Name3 它应该是这样的: Name1 Name2 Name3 2 20 200 1 10 100 3 30 300 这是我的代码: TestTR <- read.tab

我读了一个包含数据的表和一个包含相应列名的列表。现在我想用
Headrs
的内容设置
TestTR
的列名:

TestTR:
 V1  V2  V3
 2   20   200
 1   10   100
 3   30   300

 Headrs: 
 Name1  Name2   Name3
它应该是这样的:

 Name1  Name2   Name3
 2   20   200
 1   10   100
 3   30   300
这是我的代码:

TestTR <- read.table(file="C:/Users/Sabine/Downloads/UCI_HAR_Dataset/mini_tr.txt", nrows=2)  
Headrs <- read.table(file="C:/Users/Sabine/Downloads/UCI_HAR_Dataset/features.txt", nrows=3)

 colnames(TestTR) <- Headrs

  print (class(Headrs)) #  gives me    "data.frame"
  print (dim(Headrs))   #  gives me     3   2
  print (Headrs)
   V1                V2
   1  1 tBodyAcc-mean()-X
   2  2 tBodyAcc-mean()-Y
   3  3 tBodyAcc-mean()-Z       
TestTR这应该可以:

colnames(TestTR) <- c(names(Headrs))

colnames(TestTR)Headrs不是一个列表,您可以尝试以下操作:
colnames(TestTR)以及
Headrs中的内容?它应该有两行(您正在阅读两行,并且
dim()也显示了这一行),但您只给了我们一行。什么是
Headrs
?你能举个例子吗?如果headers是data.frame
colnames(TestTR)
colnames(TestTR)
colnames(TestTR)=list(Headrs$V2)
对不起,没有任何功能。headls[2]是一个列表,其中条目(而不是标题)应成为TestTR的标题