【发布时间】:2018-09-14 09:58:42
【问题描述】:
我想创建一个函数来将两列相加,其中一个单词连接两列并且有三个集合。我想将该词作为唯一参数传递,并添加一个具有相同名称的新列。像这样。
the_first_x <- c(0,0,10,0)
the_second_x <- c(10,0,10,0)
the_first_y <- c(0,5,5,5)
the_second_y <- c(5,5,0,0)
df <- data.frame(the_first_x,
the_second_x,
the_first_y,
the_second_y)
summing <- function(letter){
df$letter <- the_first_letter + the_second_letter
}
这样使用以下命令会添加一个以该字母作为名称并将总和作为其行的列
summing(x)
summing(y)
通过这样做,letter 参数无法识别,而使用 paste() 之类的东西会使该参数被括号括起来,也无法识别。
【问题讨论】: