我有几个函数,我试图在R(工作室)中实现.我将展示最简单的一个.我试图将名称附加到矢量以供以后用作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)
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误,这是非常令人费解的.我用谷歌搜索了它,但搜索太模糊/广泛.
跑步时我得到:
headers < - (headerA,compareA,compareB)
错误:"headers"中的意外"," - (headerA,"
另一个函数的第二个错误是类似的......
看起来你错过了对你的函数的调用h而只是打开了一个(:
headers <- h(headerA, compareA, compareB)
Run Code Online (Sandbox Code Playgroud)
结果是:
df new_header
1 source AA_Vs_BB
2 matches AA_Vs_BB
3 AA_Vs_BB
4 AA_Vs_BB
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
58 次 |
| 最近记录: |