【发布时间】:2019-01-04 21:32:02
【问题描述】:
我想实现如下表的输出。
任何人都可以帮助解决上述代码吗?任务主要是关于如何 使用函数插入新列。但我不确定是否必须使用 mutate_at。错误来自 length > 1 ,我对此一无所知。
谢谢!!!
## I would like to achieve the output as follow
## A B C best
## 1 2 4 Par
## 2 3 1 Lab
## 3 4 9 Par
## 4 1 0 Edu
## I tried the following codes, however, it didnt work
Library("dplyr")
Library("tidyr")
data <- data.frame(A = c(1,2,3,4),
B = c(2,3,4,1),
C = c(4,1,9,0))
best <- function(x,y,z){
if ((x>y)&(x>z)){
print("Edu")
if ((y>x)&(y>z))
print("Lab")
if ((z>x)&(z>y))
print("Par")
}
}
data_new <- mutate_at(data, vars(A:C), funs(best))
请问我该如何解决这个问题
【问题讨论】: