[英]Trying to append col.name on to a vector
I have several functions that I am trying to implement in R(studio).我有几个要在 R(studio) 中实现的功能。 I will show the simplest one.
我将展示最简单的一个。 I am trying to append names on to a vector for later use as a col.name.
我正在尝试将名称附加到向量上,以便以后用作 col.name。
# 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)
But I am getting this error and it is very puzzling.但是我收到了这个错误,这很令人费解。 I have googled it but the search is too vague/broad.
我用谷歌搜索过,但搜索太模糊/太宽泛了。
When run I get:运行时我得到:
headers <- (headerA, compareA, compareB)
标头<-(标头A,比较A,比较B)
Error: unexpected ',' in "headers <- (headerA,"错误:“headers <- (headerA,”) 中出现意外的“,”
The second error for the other function is similar...另一个函数的第二个错误类似......
It looks like you're missing a call to your function h
and just have an open (
instead:看起来您错过了对函数
h
的调用,而只有一个 open (
相反:
headers <- h(headerA, compareA, compareB)
Results in:结果是:
df new_header
1 source AA_Vs_BB
2 matches AA_Vs_BB
3 AA_Vs_BB
4 AA_Vs_BB
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.