Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.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
Function 尝试将col.name附加到向量_Function_R - Fatal编程技术网

Function 尝试将col.name附加到向量

Function 尝试将col.name附加到向量,function,r,Function,R,我在R(studio)中尝试实现几个函数。我将展示最简单的一个。我试图将名称附加到向量上,以便以后用作列名称 # Initialize headerA <- vector(mode="character",length=20) headerA[1]="source";headerA[2]="matches" # Function - add on new name h <- function(df, compareA, compareB) { new_header <-

我在R(studio)中尝试实现几个函数。我将展示最简单的一个。我试图将名称附加到向量上,以便以后用作列名称

# Initialize
headerA <- vector(mode="character",length=20)
headerA[1]="source";headerA[2]="matches"

# Function - add on new name
h <- function(df, compareA, compareB) {
   new_header <- paste(compareA,"Vs",compareB,sep="_")
   data.frame(df,new_header)
}
# Comparison 1:
compareA <-"AA"
compareB <-"BB"
headers <- (headerA, compareA, compareB)
#初始化

headerA看起来您错过了对函数
h
的调用,而只是打开了一个

headers <- h(headerA, compareA, compareB)

@oax-发生在我们当中最好的人身上:)。祝你好运
        df new_header
1   source   AA_Vs_BB
2  matches   AA_Vs_BB
3            AA_Vs_BB
4            AA_Vs_BB
...